0

I have been using:

        ShellExecute(Self.Handle,
            nil, PCHAR(format('mailto:%s ?Subject=Assunto: &Body=',[_lEmails ])),
            nil,
            nil,
            SW_NORMAL);

to send emails. No Body text so the users that have automatic signatures in their emails clients get those automatically.

Now I want to enable users to insert text as well, but if they do the text gets there but no signature. Is there a way to "force" this.

Thanks

Jlouro
  • 4,515
  • 9
  • 60
  • 91
  • 2
    This kind of functionality entirely depends on the e-mail client used, and they may behave totally different from eachother. There is no standard, as far as I know (other than some 'de facto' standards). – Andreas Rejbrand Jun 12 '12 at 17:36
  • 3
    `MAPI` is probably a better way to be sending email using the default client. It allows better control of the content. The JEDI's JCL has `JclMapi.pas`, which is a set of simple wrappers around the functionality. See [this answer](http://stackoverflow.com/a/7555895/62576) for a little more info; the question itself is about Lotus Notes email, but the linked answer refers to `JclMAPI` and a couple of it's functional wrappers. – Ken White Jun 12 '12 at 19:41
  • Sounds to me like the beginnings of an answer, @Ken. The question asks how to create e-mail to include the signature with the body text, but doesn't have an unreasonable requirement of sticking with the ill-defined "mailto" technique, so an answer of "Use MAPI" is good. – Rob Kennedy Jun 12 '12 at 21:10
  • @Rob, done. Thanks for the suggestion; I was going to wait to see if the poster asked for one, but re-reading I do see that there was no restriction. – Ken White Jun 12 '12 at 22:06
  • maybe you'd just create *.eml or *.msg file and ShellExecute it ? – Arioch 'The Oct 15 '12 at 09:22

2 Answers2

4

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.

Ken White
  • 123,280
  • 14
  • 225
  • 444
2

On ensuring the default signature appears (if that was the crux of the question, if not sorry, I have misread), then appears you may be out of luck (as I've been trying to do this).

The below MS article appears to say "no". It appears to imply that versions of Outlook up to 2010 wont support defaulting email signatures when creating emails via MAPI. It doesn't seem to offer much of a reason, and advises that you simply use the "insert signature" option in the email dialog (which to me, isnt a real help when you may want it defaulted and perhaps for the email to just "go" without user intervention).

http://support.microsoft.com/kb/2544665

DrHazy
  • 41
  • 4
  • 1
    Care to write a summary of the MS article? Why does it say "no"? – nalply Oct 13 '12 at 13:45
  • Not sure i can add much beyond what the article says, but it appears to imply that versions of Outlook prior to 2010 wont support defaulting email signatures when creating emails via MAPI. It doesnt seem to offer much of a reason, and advises that you simply use the "insert signature" option in the email dialog (which to me, isnt a real help when you may want it defaulted and perhaps for the email to just "go" without user intervention). – DrHazy Oct 13 '12 at 13:51
  • You can edit your own answer. I did that for you now, but in future, if you give good answers and summaries, you will get more upvotes. – nalply Oct 13 '12 at 13:54