Mega Code Archive

 
Categories / Delphi / LAN Web TCP
 

How to send eMail using the default Mail Client

Title: How to send eMail using the default Mail Client Question: Most windows installations will implement the Web 'mailto:xyz@xyz.com' command, using the 'default mail client' Microsoft eMail clients will take a command line that includes the destination, subject and bodytext. Using this information, you can automate the composing of an eMail from your Delphi code, leaving the user the choice to click 'Send' or not. Answer: USES SHELLAPI; Procedure AutoSendMail; Var EMailDestinationString,SubjectString,Line1String,Line2String,mailstring:String; BEGIN EMailDestinationString:='gbamber@bamber.com'; SubjectString:='Message Subject'; Line1String:='This is the first line'; Line2String:='This is the second line'; // You can have multiple destinations seperated by a semicolon // mailstring:='mailto:' + EMailDestinationString + '?subject=' + SubjectString + '&body='+ Line1String + '%0d' + Line2String; if (ShellExecute(0,'open',PChar(mailstring),'','',SW_SHOWNORMAL) ShowMessage('Auto method failed.'); END;