Send HTML mail with images - Paul Courbis


   

CAUTION !

Please read this...



You'll fin below this text a semi-automated translation of the original website. Texts will be gradually reviewed to make them as accurate as possible but it's strongly recommanded to read the original page (preview on the right side of this text) :

Link to the original article


(if this link is broken, please go to the original website's root page and look for wanted data. Sorry about that).


Some parts of this website will never be translated to English. Part of them are user's comments that are not transfered from the French (original) version to this version. Obvously, you can leave your own comments here but they wont be transfered to the French version.

You can send comments or suggestions to the webmaster.

   
Paul Courbis


Send HTML mail with images

Thursday 15 July 2010, by Paul Courbis

It is sometimes useful to send, automatically, an email formatted in HTML with images "embedded", ie included in the email itself (and not stored on a remote server).

On Linux, there is a simple solution, using the utility "metasend. This requires creating an html file (ex: mail.html) containing the body of the message and referencing the images via an id. For example:

 
     Voici une image : <img src="cid:id_001.gif">
 

We then use "metasend" to send the message as follows:

metasend -b                                  
  -F from@domewhere.com                    
  -t someone@somewhere.com                  
  -s "sujet du message"                    
  -/ related                                
  -m text/html -f mail.html                
  -n -m "image/gif" -f image1.gif -i '<id_001.gif>'
</id_001.gif>

Explanation of Options (see here ): —b indicates that metasend fontionne in batch mode - F-address of the sender of the mail - Does the recipient’s address —s subject line - - / indicates that the mode of transmission MIME is "related" (ie multiple attachments together) —m indicates the type of the first attachment (text / html) —f name of the first to join —n indicates that it passes the second attachment —m gives its type (image / gif) —f file name of the second to join —i specifies the ID of the object (you can reference the href in mail body)

This last line (-n .../...) can be repeated as many times as there are pictures to attach, each time using a different ID.

Note: The type specified must reflect the real image type pain of not being able to display it in some cases (eg Internet Explorer in consultation with Gmail).

Reply to this article