smithvoice.com
 Y'herd thisun? 

“Seen the funny and GREAT movie "the Big Dish?" Heading to Cali for a vaca? You have to visit the Goldstone array complex. Check this to see why”

from Visit to Goldstone by Smith

Full site or winform auto-email

TaggedCoding, DotNet, ASP.Net

(by smith first published in Feb 2000 Visual Basic Programmers Journal)

 Need the same simple power in .Net? Use Process.Start([mailto string as described below])

One of the most used lines of Win32 API code is ShellExecute.   It's great because you can pass any file name and if the file's extension is associated to a registered program on the user's machine, then the correct application will open and the file will be played or displayed.

It's almost common knowledge that ShellExecute also has internet power.  If you pass a URL, the user's default 32bit web browser will open and connect to the site. If you preface an email address with "mailto:" then the user's default 32bit eMail client will open a new email with the address filled in.

Here's how to automatically get a lot more than just the email addresses:

note:  not all email clients accept multiple mailto extensions, some less-powerful email systems only accept a single extension.   However, if your customers have a up to date MS-mail email standard such as Exchange/Outlook (the Full Outlook not Express, Express is a freebie and thus has limitations such as not accepting the &Attach commandline argument) then all extensions are available.

If you want to include a list of CC recipients, BCC recipients, your own Subject text and/or Body text, just create a string variable, add the list of primary addresses (separated by semicolons) then a question mark character "?" and element strings prefaced as follows:

  • For CCs (carbon copies): &CC= (followed by list)

  • For Blind CCs: &BCC= (followed by list)

  • For Subject Text: &Subject= (followed by text)

  • For Body Text: &Body= (followed by text)

  • To Add an Attachment (must be the last in the list): &Attach= (followed by a valid file path)

Note that the first element (directly after the "?") does not need an ampersand, the ampersands are used to separate the elements.  Plus, you can not have spaces between the ampersands and tags, or between the tags and the equal signs.

You don't have formatting options so body text will all be one single paragraph but still, it sure beats automating a full email program!

We've created a fully operable demo project that shows just how easy it really is, it's vb5/vb6 and includes no added references. 

Hope it helps!

(BTW: almost all of the above is possible in HTML MailTo tags, here is a sample:

<A HREF="mailto:billg@microsoft.com?subject=Feedback From VisualBasic Sitelett smithvoice.com/vbfun.htm&CC=smith@smithhome.org&BCC=fred@fred.net;bill@home.com&body=hello how are you">feedback@smithvoice</A>

We have yet to get HTML to do the attachments but, as you will see in the demo, attachments are no problem from VB!)

Smith

click here to get (just 2k!)

***- just a note:  DDE programs like Word and Excel can crash with a ShellExecute ... it is advised to use ShellExecuteEx on apps that use DDE.

Jan 2000 update:

We just received this note and it may help you in some of your email/fax development.

"I just got through implementing your Tech Tip from the VBPJ 101 Tech Tips.   It works for me...kinda. I found myself wishing that they had published your email address. THEN...by coincidence...I was searching the MS newsgroup and found your response to another persons enquiry...and your URL.

NOW, maybe I can get an answer from you ?!? When I implement your solution I get the Outlook message window...complete with the info that I have supplied. BUT, it doesn't send the  message. I have to click 'Send'. Is there any way that the message can be sent automatically?" - Larry Woods

Hi Larry:

Using ShellExecute will only pass the message to the default email client software and there are restrictions to the different software clients based on the commandlines that each software system was made to work with.

Things get a little trickier once you want to actually send the email automatically.

Trickier in that some email uses MAPI (which can now be fully automated with ease using CDO, for some details, see www.smithvoice.com/youcan.htm for CDO faxing demos)

... and some email software does not use MAPI.

If you are using full Outlook or an Exchange client then MAPI is used and you can use either MAPI or CDO with MAPI to send the messages, move them around the folder systems, check the sent status and lots more.

However, if you or your clients are using a non-MAPI email system like Eudora, Lotus NotesMail, Pegasys, Netscape Communicator, etc, etc then you will have to code to the exact system that those software clients use, if you can.

If Netscape's is the system then it can be coded using DDE (but it is a real pain in the neck since their DDE calls use styles that are ok for C++ but get in the way of VB)

If your clients are using Eudora, then you might have no way of getting at the program for any automation. Eudora, by my old experience, is a closed system. They made an email system, but they did not make one that developers could enhance.

You follow all this?

If MS were the only player then there would be a standard and coding would be simple ... but MS is not the only player.

Check out that page I mentioned, and if you can take a look at Amundsen's MAPI, TAPI & SAPI Developer's Guide for more MAPI email information (lots more!)

But the tip that was published was based on the ShellExecute ability to pass the commandlines to the program that is set in the user's registry as linked to the MAILTO command, so as-is it can only pass in the commandlines and then it is up to the individual software to take it from there.

-Robert Smith

Update:

Mr. Smith,

Doing some research I found that I can add "%0a%0d" to the body of an Outlook express message to force carriage return line feed.  I found MS articles Q188019 and Q192341 which supported your information on this subject...

Larry Rebich



home     who is smith    contact smith     rss feed π
Since 1997 a place for my stuff, and it if helps you too then all the better smithvoice.com