Jump to content

How to send html and plain text mail in one


Recommended Posts

Hi,

I am currently working on a script that can send an e-mail to a list of recipients, using the _InetSmtpMail and _InetSmtpMailCOM() functions. Everything works perfectly, but now I wonder how to send an e-mail in both html and plain text, so that the e-mailclient of the recipient decides which one to display? Sort of what they often use for online newsletters.

I believe it is called multipart/alternative in MIME and I searched for it on the autoit forums, but I could only find one topic. There they referred to _InetSmtpMailCOM(), but I can't seem to figure out how to manage it with this function. I would like to do exactly what LOULOU said in his topic:

LOULOU, on Jul 9 2006, 08:26 PM, said:

In fact here is what i want to do :

'Content-Type: multipart/alternative;

boundary="----=_NextPart_000_000A_01C6A396.0B0D9820"' & @CRLF & _

"------=_NextPart_000_000A_01C6A396.0B0D9820" & @CRLF & _

'Content-Type: text/plain;charset="iso-8859-1"' & @CRLF & _

"Content-Transfer-Encoding: quoted-printable" & @CRLF & _

Here the text in plain format

"------=_NextPart_000_000A_01C6A396.0B0D9820" & @CRLF & _

'Content-Type: text/html;charset="iso-8859-1"' & @CRLF & _

'Content-Transfer-Encoding: quoted-printable' & @CRLF & _

And here the text in html format

"------=_NextPart_000_000A_01C6A396.0B0D9820--" & @CRLF & _

@CRLF

Anybody knows how to achieve this?

Edited by Michiel78
Link to comment
Share on other sites

Hi,

I am currently working on a script that can send an e-mail to a list of recipients, using the _InetSmtpMail and _InetSmtpMailCOM() functions. Everything works perfectly, but now I wonder how to send an e-mail in both html and plain text, so that the e-mailclient of the recipient decides which one to display? Sort of what they often use for online newsletters.

I believe it is called multipart/alternative in MIME and I searched for it on the autoit forums, but I could only find one topic. There they referred to _InetSmtpMailCOM(), but I can't seem to figure out how to manage it with this function. I would like to do exactly what LOULOU said in his topic:

Anybody knows how to achieve this?

Already found a way to make it work!

$TextBody
$HTMLBody ;replace $as_Body with a text and html body

$rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $TextBody, $HTMLBody, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl) ;add the new $TextBody and $HTMLBody to the $rc string

Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_TextBody = "", $as_HTMLBody = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0) ;also add them both to the _InetCOM

;Replace in the _InetCOM:
If StringInStr($as_Body,"<") and StringInStr($as_Body,">") Then
$objEmail.HTMLBody = $as_Body
Else
$objEmail.Textbody = $as_Body & @CRLF
EndIf

;With:
$objEmail.HTMLBody = $as_HTMLBody
$objEmail.Textbody = $as_TextBody & @CRLF
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...