Link to home
Create AccountLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

Automaticly open Email-message with HTML in the body

Dear Experts,

I have read and tried many articles on the Internet about Email in Delphi.

What I want is: When the user clicks on a button then the default E-mail client
starts with an New Message form, like what this procedure does:

uses
  ShellApi;

procedure TForm1.Button1Click(Sender: TObject);
var
  mail: string;
begin
  mail := 'mailto:you@you.com' + '?subject=hello' + '&cc=me@me.com' + '&body=Delphi is cool! ;)';
  ShellExecute(Self.Handle, 'open', PChar(mail), nil, nil, SW_SHOWNORMAL);
end;

But instead of a string '&body=Delphi is cool! ;)' in the body-section
I want HTML (TStrings) in the body-section, like this:

var
  html: TStrings;
begin
  html := TStringList.Create();
  html.Add('<html>');
  html.Add('<head>');
  html.Add('</head>');
  html.Add('<body><h1>Hello</h1>');
  html.Add('This is a picture of us!</body>');
  html.Add('</html>');

So,
1. The user clicks on a button
2. The default email-clients starts with a new message form
3. With just the body-section filled with HTML

* The email must not be send automatically, that's the job of the user *

Does any one know a solution?

Thank you in advanced.

Greetings,

Peter Kiers
Avatar of MerijnB
MerijnB
Flag of Netherlands image

the only good way of achieving this is to use automation of each different mail client (if this is available).
In other words, this is very very hard to achieve properly.
Avatar of Peter Kiers

ASKER

I know it possible, because I know another programm that has that feature too.
I have tried many examples, but the ones with HTML in the body-section actually
send the email, and I don't want that.

Peter

 
and this other program, which email clients does it support?
all
the only thing which will 'work' is what you described in your first post, the the problem is that the size of the command line is limited and that you don't know to what, so unless you will always write very short mails to very few people, it will be very likely that your mail contents will be truncated.
With this procedure you can  add HTML in the body-section
but is send the mail, and I don't want that.

http://www.howtodothings.com/computers/a791-sending-html-emails-with-indy.html

And this procedure below does not send the mail but HTML
in the body-section is not possible:

http://www.techtricks.com/delphi/sendmail.php

P.
ASKER CERTIFIED SOLUTION
Avatar of MerijnB
MerijnB
Flag of Netherlands image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi,

I have tested your example. But the text in the
body-section is text and not HTML.

Peter
It does work with my mail client, thunderbird.

It seems that it just isn't possible: http://support.microsoft.com/kb/268440

Did you try:

var
  html: TStrings;
  mail: string;
begin
  html := TStringList.Create();
  html.Add('<html>');
  html.Add('<head>');
  html.Add('</head>');
  html.Add('<body><h1>Hello</h1>');
  html.Add('This is a picture of us!</body>');
  html.Add('</html>');
  mail := 'mailto:you@you.com' + '?subject=hello' + '&cc=me@me.com' + '&body=' + html.Text;
  ShellExecute(Self.Handle, 'open', PChar(mail), nil, nil, SW_SHOWNORMAL);
Oke, I quess it just isn't possible.
Thank you for trying.

500 comming your way.

Peter Kiers
Avatar of rob_emacs
rob_emacs

There is a work-around which I've been using. If you save the html you want to send out to a file and then use the function above to send a blank body with a .htm file as an attachment then Outlook picks this up as a HTML email message.

SendMailMAPI('test subject', '', 'c:\htmlbody.htm' , 'me', 'me@here.com', 'test', 'you@there.com');
Thanks

Peter Kiers