Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send an email that contains both the HTML and plain text versions?

Status
Not open for further replies.

JoJoH

Programmer
Joined
Jan 29, 2003
Messages
356
Location
US
Hi all,

Is there anyway to send an email that contains both the HTML and plain text versions? (allowing the client software to pick and choose). I've found a PHP tutorial for this but is there any VBscript/ASP once out there? Please advice.

Thanks in advance!


JoJoH

 
Just like you would normally send HTML. Example below:
<%
myHTML=&quot;<html><head><style type=&quot;&quot;text/css&quot;&quot;>TD{font-family:tahoma;font-size:10px;}A:Hover{color:red;}</style></head>&quot;
myHTML=myHTML & &quot;<body bgcolor=&quot;&quot;yellow&quot;&quot;><table border=&quot;&quot;0&quot;&quot; width=&quot;&quot;450&quot;&quot;><tr><td>This is a test email. &quot;
myHTML=myHTML & &quot; Were it a real email then the end of the world would be near.&quot;
myHTML=myHTML & &quot;<br>You can view the end of the world &quot;
myHTML=myHTML & &quot;<a href=' target=&quot;&quot;_blank&quot;&quot;>HERE</a>&quot;
myHTML=myHTML & &quot;</td></tr></table></body></html>&quot;
' the next line is not HTML - it will render as text after the HTML portion
myHTML=myHTML & vbcrlf & vbcrlf & &quot;This is some text that is not part of the HTML&quot;

myTo=&quot;you@somewhere.com&quot;
myFrom=&quot;me@elsewhere.com&quot;
myCC=&quot;them@overthere.com&quot;
mySubject=&quot;EMAIL TEST&quot;
myBody=myHTML
SET myMail = server.CreateObject(&quot;CDONTS.NewMail&quot;)
myMail.To = myTo
myMail.From = myFrom
myMail.CC = myCC
myMail.Subject = mySubJect
myMail.BodyFormat = 0
myMail.MailFormat = 0
myMail.Body = myBody
myMail.Send
Set myMail = Nothing
%>
 
I know that, if you use CDO (rather than CDONTS), you can set the msg.textBody and msg.HTMLBody separately, and the client will pick it's preferred version.

Sorry, that's not terribly helpful.

Here's some sample code that I use...

First, these lines go top-side...
Code:
<!--METADATA TYPE=&quot;typelib&quot; UUID=&quot;CD000000-8B95-11D1-82DB-00C04FB1625D&quot; NAME=&quot;CDO for Windows 2000 Type Library&quot; -->
<!--METADATA TYPE=&quot;typelib&quot; UUID=&quot;00000205-0000-0010-8000-00AA006D2EA4&quot; NAME=&quot;ADODB Type Library&quot; -->

...then we write our mail message
Code:
' mail section - setup of cdo for 2000
dim iMsg, Flds, iConf
set iMsg  = CreateObject(&quot;CDO.Message&quot;)
set iConf = CreateObject(&quot;CDO.Configuration&quot;)
set Flds  = iConf.Fields

Flds(cdoSendUsingMethod) = cdoSendUsingPort
Flds(cdoSMTPServer) = &quot;YOUREXCHANGESERVER&quot; 
Flds(cdoSMTPServerPort)	= 25
Flds(cdoSMTPAccountName) = &quot;Domain User Name&quot;
Flds(cdoSMTPAuthenticate)= cdoBasic ' 1
Flds(cdoSendUserName)    = &quot;DOMAIN\USERID&quot;
Flds(CdoSendPassword)    = &quot;PASSWORD&quot;
Flds.Update
	
with iMsg
  set .Configuration = iConf
  .To = sendToVar
  .Subject = subjVar
  .From = &quot;Sender Name&quot;
  .Sender = &quot;validEmailAddress@somewhere.com&quot;
  .ReplyTo = &quot;validEmailAddress@somewhere.com&quot;
  .HTMLBody = htmlVar
  .TextBody = textVar
  .Send
end with
set Flds  = nothing
set iConf = nothing
set iMsg  = nothing
%>

Note that, you MUST supply a valid User & Password, and you MUST have either a Sender or ReplyTo... which should be a valid email address.
 
Oh, also note that the valid &quot;DOMAIN\USER&quot; and Password are NOT necessarily the &quot;.Sender&quot; or &quot;.ReplyTo&quot; values.

I use a generic &quot;DOMAIN\USER&quot; account to acccess our EXCHANGE server, then send system-wide emails (to employees of our company... not spam!), and to generate HTML invitations to corporate events, then set the ReplyTo and Sender values to my address or our Administrative staff address. Works pretty easily.
 
Thanks Veep, thanks Mr3Putt for the replies!

Veep: Thanks for your reply! Now if the recipient does not support html, all he sees will be the plain text part of the message right? Now if the recipient does support HTML emails, is there anyway to hide the plain text part? Please advice, thanks!

Mr3Putt Thanks for your reply! I wish I could do &quot;and the client will pick it's preferred version.&quot; with CDONTS instead of CDO because I am currently using CDONTS, any idea? Please advice, thanks!

Thanks again!

JoJoH

 
Well, I used to work with CDONTS, then I just started using CDO instead... I can't remember if I had to do anything in particular, other than including the META's at the top of my page.

I'm pretty sure CDO is availabe in a default IIS installation.

Try it. If it works, then you're good to go.

Perhaps some other fine Tek-Tipsters can comment on the various merits/deficiencies of CDO vs CDONTS.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top