2011/12/21

Send attachment with default email client

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:

1. 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" 

2. Or use SendToVB a small free software that allows you to send in a programmed way email with attachments using the default email client, and above is compatible with ALL Client (Thunderbird included). Here is the screen that summarizes the commands and options available:

Also this software is to be used from the 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



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


An image of use with Thunderbord is here. SendToVb automatically open your Default Email Client (Thunderbird in this case) and compose the email like in Window.





Notes for software developers:

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 written in Visual Basic 2005 and requires the installation of .NET Framework 2.0 runtime which is often already installed on new PCs. Internally automatically uses MAPI functions when to send emails with attachments, and use the command mailto to send email without attachments.

SendToVB is available here for download 



How would you like it to be improved on this article? 
Leave me a comment with your thoughts or requests!

If you find this article useful please click on the button "G +1" in the bottom of the post before the "Comments" section!

No comments:

Post a Comment