We help IT Professionals succeed at work.

Send Html mail

Zuhair070699
Zuhair070699 asked
on
Hi,

Is there is a way to send html page using NMSMTP component without using external component?

Thanks,
Comment
Watch Question

Commented:
All you need to do to send HTML mail is to add a custom header to the message:
  Content-type: text/html

The body of the message would contain HTML code.

The one thing you will have problems with, is including
images in the message. If you take a close look at the source of MS Outlook Express HTML messages, you'll notice that the images UUencoded and included in the message - the links to the images look like: mk:image1.gif
or something.

Commented:
Hello Zuhair,

Just set the "Content-Type:text/html" header.

Best Regards

Cesario

Author

Commented:
Hi,

Thank you all .. I use NMSMTP  componant, so where shall I put the header: Content-type: text/html  ??

Commented:
Hi Zuhair,


  with NMSMTP1 do
    begin
      FinalHeader.Add('Test');
      PostMessage.ToAddress.Add('prioux@videotron.ca');
      PostMessage.FromAddress := 'prioux@videotron.ca';
      PostMessage.Subject     := 'Sending html format';
      PostMessage.Date        := DateToStr(Date);
      PostMessage.Body.LoadFromFile('C:\test2.html');
      SubType := mtHtml;
      Connect;
      SendMail;
      Disconnect;
   end;

Best Regards

Cesario

Author

Commented:
Thanks,

But I still got plain text messsage !

Any idea ?

Commented:
Make sure the body of the message has HTML tags:

<HTML>
 <BODY>
  <P>
    Hi, this is an HTML message.
 </BODY>
</HTML>

Author

Commented:
Still the same problem.. do you test your code ?

Commented:
Sorry, the HTML code should've included some markup:

<HTML>
<BODY>
 <P>
   Hi, <u>this</u> is an <b>HTML<b> <i>message<i>.
 <hr>
 <P align="center">
   <font color="silver">End of Message</font>
</BODY>
</HTML>

I use the ICS component suite - all's I gotta do to send HTML mail is add a custom header
 Content-type: text/html
then set the body string to my HTML source(above).

To 'debug', you should try to view the source of the message in your mail client to see if it contains the HTML tags. If you're using Outlook Express this should be under File->Properties, if you're using Outlook (Office), then save the message and open the
.msg file in notepad or something.

rondi.

Author

Commented:
I am really appretiate your help but could you please take a look to my code:


 NMSMTP1.Connect;
 NMSMTP1.FinalHeader.Add('Content-Type:text/html');
 NMSMTP1.EncodeType := uuMime;
 NMSMTP1.PostMessage.FromAddress := 'System';
 NMSMTP1.PostMessage.FromName := 'System Administrator';
 NMSMTP1.PostMessage.ToAddress.Clear;
 NMSMTP1.PostMessage.ToAddress.Add('my@email.me');
 NMSMTP1.PostMessage.Body.LoadFromFile('c:\test2.html');
 NMSMTP1.PostMessage.Subject := 'title';

 If NMSMTP1.Connected then
       NMSMTP1.SendMail;

========================================================
test2.html file is what you posted:

<HTML>
<BODY>
<P>
  Hi, <u>this</u> is an <b>HTML<b> <i>message<i>.
<hr>
<P align="center">
  <font color="silver">End of Message</font>
</BODY>
</HTML>


========================================

after i run the script I got an email with plain text NOT html.

Any idea?

Thanks


All-around developer
CERTIFIED EXPERT
Commented:
This works for me:

  NMSMTP1.Connect;
  NMSMTP1.FinalHeader.Add('Content-Type:text/html');
  NMSMTP1.EncodeType := uuMime;

  // DONT FORGET THIS!!!
  NMSMTP1.SubType := mtHTML;  

  // You SHOULD set the domain in the From Address,
  // some systems won't let you send without it
  NMSMTP1.PostMessage.FromAddress := 'system@myemail.com';

  NMSMTP1.PostMessage.FromName := 'System Administrator';
  NMSMTP1.PostMessage.ToAddress.Clear;
  NMSMTP1.PostMessage.ToAddress.Add('me@myemail.com');
  NMSMTP1.PostMessage.Body.LoadFromFile('c:\test1.html');
  NMSMTP1.PostMessage.Subject := 'HTMLMail';
  If NMSMTP1.Connected then
        NMSMTP1.SendMail;
Eddie ShipmanAll-around developer
CERTIFIED EXPERT

Commented:
With this line:
 NMSMTP1.SubType := mtHTML;  

These are not needed:
 NMSMTP1.FinalHeader.Add('Content-Type:text/html');
 NMSMTP1.EncodeType := uuMime;
Zuhair:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
CERTIFIED EXPERT

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

split points between Cesario and EddieShipman

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer

Explore More ContentExplore courses, solutions, and other research materials related to this topic.