How to send email with attachments in a way programmed and automated by using the default e-mail client software whatever it is (Outlook, Outlook Express, Windows Live Mail, Thunderbird, etc.).?
Essentially there is the need to have a system to compose an email message containing: sender, recipient, title, subject and attachment files and to automatically open the default email client with the message pre-compiled so that the user has to carry only sending.
There are at least a couple of methods:
You can use the command mailto with the attachment parameter:
From a command prompt (click Start | Run, then type cmd and press enter) you can launch the default email client through a mailto hyperlink.
Please note that NOT all Email Clients support the parameter for attachments (such as Thunderbird does not accept it).
mailto:me@example.com?Subject=Hi&Body=See+attached+file&Attach="C:\readme.pdf"
mailto:me@example.com?Subject=Hi&Body=See+attached+file&Attach="C:\readme.pdf"
2. SENDTOVB
"Programmatically send emails with attachments using the default email client"
You can use the tool SendToVB, a small free command line utility software that allows you to send email with attachments by a programmed way using the default email client!
SendToVb is compatible with ALL Client (Thunderbird included). Here is the screen that summarizes the commands and options available:
SendToVB command and options available |
You can use the software with Windows command prompt.
The syntax is simple:
SendToVB -files <attachment file1> -body <text of mail> -to <email address> -subject <content>
Example:
SendToVB -file c:\readme.txt -body "Hello here the document for you" -to marc@example.com -subject "Important"
The commands (flags) are:
-files <file1>... <fileN> with which you can send multiple attachments in the same email.
-body <text> which is part of the body of the message enclosed in double quotes (").
-bodytext <bofyfile.txt> that can be used as an alternative to -body when the email must contain a very long message. It allows you to specify the text file that contains the body of the email.
-to <address1>; <address2> with which you can also specify multiple recipients separated by a semicolon (;)
-cc <address1>; <address2> with which one can point in Carbon Copy also multiple recipients separated by a semicolon (;)
-bcc <address1>; <address2> with which one can point in Blind Carbon Copy even multiple recipients separated by a semicolon (;)
-subject <text> with which you assign the title of the email
-mailto with which to force SendToVB to use the mailto method (instead of the MAPI functions) but that may not work properly when inserting attachments!
All commands (flags) can be abbreviated with the first letter, eg -subject becomes -s
-body <text> which is part of the body of the message enclosed in double quotes (").
-bodytext <bofyfile.txt> that can be used as an alternative to -body when the email must contain a very long message. It allows you to specify the text file that contains the body of the email.
-to <address1>; <address2> with which you can also specify multiple recipients separated by a semicolon (;)
-cc <address1>; <address2> with which one can point in Carbon Copy also multiple recipients separated by a semicolon (;)
-bcc <address1>; <address2> with which one can point in Blind Carbon Copy even multiple recipients separated by a semicolon (;)
-subject <text> with which you assign the title of the email
-mailto with which to force SendToVB to use the mailto method (instead of the MAPI functions) but that may not work properly when inserting attachments!
All commands (flags) can be abbreviated with the first letter, eg -subject becomes -s
In addition, for those who experience problems with too many parameters and receive the message "command line too long" you can use a second method:
-list <listfile.txt> indicates where the text file that contains a single line with all specified commands to be used for sending mail
SendToVb automatically open your Default Email Client (for example Thunderbird) and compose the email like in Window.
a. Since SendToVB is a small stand-alone tool, it can also be used by third-party software to automate the procedures for sending mail. A hypothetical third-party software written in Visual Basic. NET or C# might contain within it a line of code that calls a shell command within the SendToVB.
For example:
System.Diagnostics.Process.Start ("SendToVB -to you@example.com -file C:\readme.txt");
b. SendToVB is coded in Visual Basic 2005 and requires the installation of .NET Framework 2.0 runtime which is often already installed on new PCs. Internally it automatically uses MAPI functions when it has to send emails with attachments, and use the command mailto to send email without attachments.
Notes from the Author:
CHANGELOG:
Version 1.2 - Added -cc and -bcc parameters
Version 1.1 - The First !
Notes from the Author:
- The name "SendToVB", VB stands for Visual Basic 2005 because this software is wrtitten with this .NET language.
- The source are based on work of this two autors
- David M Brooks - "Programmatically adding attachments to emails in C# and VB.NET"
- Larry Steinle - "Split Function that Supports Text Qualifiers"
- SendToVB use automatically MAPI function when the message have attachments and use Mailto when email have NOT attachments.
- SendToVB version1.2 is Freeware.
CHANGELOG:
Version 1.2 - Added -cc and -bcc parameters
Version 1.1 - The First !