You can use MAPI instead (the Messaging Applications Programming Interface
), which gives you much better control over the email, and allows things like attachments. You can also choose whether to show the user's email client "compose" window or add directly to the outbox. (The outbox functionality is usually restricted now because of changes to Windows security, especially where MS Outlook is concerned.)
The quickest, easiest way is to use something like the JEDI Code Library JCLEMail
. It's a wrapper around SimpleMAPI, which makes it very easy (code was taken from an older app, and was based on a sample from the JCL demo):
EMail := TJclEMail.Create;
try
EMail.Recipients.Add(AnsiString(EMailAddress), AnsiString(EMailName));
EMail.Subject := AnsiString(Subject);
EMail.Body := AnsiString(Body);
EMail.HtmlBody := False; // True if it's HTML email
// Send attachment if wanted
EMail.Attachments.Add(AnsiString(FileName));
EMail.Send(True); // True to show default email, false to add to outbox
finally
EMail.Free;
end;
The drawback to SimpleMAPI
is that it may be a short-term solution (although it's still around in Win7 64-bit and earlier, I can't speak for Windows 8). According to MSDN,
[The use of Simple MAPI is discouraged. It may be altered or unavailable in subsequent versions of Windows.]
The drawback to MAPI
is that it relies on a MAPI
client being installed. Fortunately, almost any software that supports mailto
should support MAPI
as well; Outlook does, for instance, and so does Mozilla Thunderbird.