• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1212
  • Last Modified:

Html Email Not Showing Properly .Shows HTML Tags.(ASP/IIS)

Hi Friends,

I am trying to send HTML EMAIL in ASP using CDOSYS.

But After receving email in Inbox it shows HTML tags not proper HTML email.

please help me to resolve the issue.

Email composed in HTML as :
---------------------------------------------------=====================

<TABLE style=""BORDER-RIGHT: #000033 1px solid; BORDER-TOP: #000033 1px solid;

BORDER-LEFT: #000033 1px solid; BORDER-BOTTOM: #000033 1px solid; TEXT-ALIGN: left""

cellSpacing=0 cellPadding=0 width=538 align=center border=0>
<TBODY>
<TR>
<TD>
<DIV align=center>
<TABLE borderColor=#000080 cellSpacing=0 cellPadding=0 width=""100%"" border=3>
<TBODY>
<TR>
<TD><IMG src=""http://www.store.org/store/EI/email_design.gif"" width=536 border=0></TD></TR>
<TR>
<TD align=left>
<TABLE cellSpacing=0 cellPadding=0 width=536 border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=12 border=0>
<TBODY>
<TR>
<TD vAlign=bottom 0px>
<P align=left><FONT size=2 12px; LINE-HEIGHT: 15px; FONT-FAMILY: verdana, helvetica, sans

serif><BR><BR></FONT><FONT 12px; LINE-HEIGHT: 15px; FONT-FAMILY: verdana, helvetica,

sans serif>Dear #NAME#,</FONT><FONT size=2 12px; LINE-HEIGHT: 15px; FONT-FAMILY:

verdana, helvetica, sans serif><BR><BR></FONT><SPAN style=""FONT-SIZE: 12pt; FONT-FAMILY:

'Times New Roman',serif"">Thank you for your order.</SPAN><FONT 12px; LINE-HEIGHT: 15px;

FONT-FAMILY: verdana, helvetica, sans serif><BR><BR><FONT face=Arial>By now you should

have already received your order from us.</FONT></FONT><SPAN style=""FONT-SIZE: 12pt;

FONT-FAMILY: 'Times New Roman',serif""><BR><BR>We pride ourselves on delivering the best

possible shopping experience to you and all of our customers. That means from the moment you enter

our store to the moment your order is delivered to your door - we are dedicated to your

satisfaction.<BR><BR>We would greatly appreciate it if you would take the time to fill out a 1 minute

survey on your shopping experience with our company.<BR><BR>Just click on the link below, enter

your Order/Invoice Number and choose a star rating. All comments are also greatly

appreciated.</SPAN><SPAN style=""FONT-FAMILY: 'Times New

Roman',serif""><BR>&nbsp;</SPAN></P>
<P class=MsoNormal>Your order/Invoice number: <B><FONT face=""Courier

New"">#ORDER#</FONT></B></P>
<P align=left><BR><CODE><FONT face=Arial color=#336699 size=4><A

href=""https://www.pricegrabber.com/rating_merchrev.php?retid=5656"">Click here to leave a review

about your order!</A></FONT></CODE></P>
<HR>

<P align=left><B><FONT face=""Courier New"">Order Number:

#ORDER#</FONT><CODE><BR>Payment Method:

</CODE></B><CODE>#PAYMT#</CODE><B><SPAN style=""FONT-FAMILY: 'Times New

Roman',serif""><BR></SPAN></B><CODE><B>Total: #TOTAL#<BR></B></CODE><B><SPAN

style=""FONT-FAMILY: 'Times New Roman',serif""><BR></SPAN></B><CODE><FONT

face=Arial><A href=""https://www.pricegrabber.com"">#REVIEWS#</A></FONT></CODE></P>
<HR>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD style=""PADDING-RIGHT: 12px; PADDING-LEFT: 12px"" align=left colSpan=2

height=12><FONT style=""FONT-SIZE: 12px; LINE-HEIGHT: 15px; FONT-FAMILY: verdana,

helvetica, 'sans serif'"" size=2 12px; LINE-HEIGHT: 15px; FONT-FAMILY: verdana, helvetica, sans

serif>
<TABLE cellSpacing=0 cellPadding=12 bgColor=#fdffda border=0>
<TBODY>
<TR>
<TD align=left>
<P class=MsoNormal><FONT size=2>Sincerely,<BR><BR>Customer Support

Team<BR><BR>Store.org</FONT></P></TD></TR></TBODY></TABLE></FONT></TD></TR>
<TR>
<TD align=middle

width=536><BR></TD></TR></TBODY></TABLE></DIV></TD></TR></TBODY></TABLE>
<TABLE style=""TEXT-ALIGN: left"" width=538 align=center>
<TBODY>
<TR>
<TD align=middle><FONT face=verdana, size=1 sans serif 10px>© 2007 #STORE# All rights

reserved.</FONT></TD></TR></TBODY></TABLE>


=========================================================
CALLING FUNCTION
call sendmail (CustName, pEmailAdmin, emailTo, emailSubject, CustMessage, 0)
 
FUNCTION IS DEFINED AS :
-----------------------------------
<%
Function sendMail(fromName, fromEmail, toEmail, subject, body, contType)
 
	if UCase(debugMode) = "Y" then
		on error resume next
	end if
	select case mailComp
		case "1" 'JMail
			call JMail(fromName, fromEmail, toEmail, subject, body, contType)
			
		case "2" 'CDONTS
			call CDONTS(fromName, fromEmail, toEmail, subject, body, contType)
			
		case "3" 'Persits ASPEmail
			call PASPEmail(fromName, fromEmail, toEmail, subject, body, contType)
			
		case "4" 'ServerObjects ASPMail
			call SOASPMail(fromName, fromEmail, toEmail, subject, body, contType)
			
		case "5" 'Bamboo SMTP
			call bamboo(fromName, fromEmail, toEmail, subject, body, contType)
			
		case "6" 'CDOSYS
			call CDOSYS(fromName, fromEmail, toEmail, subject, body, contType)	
	end select
	
	on error goto 0
	
end Function
 
'JMail (v4.3)
Function JMail(fromName, fromEmail, toEmail, subject, body, contType)
	dim mail,I
	set mail = server.CreateObject("JMail.Message")
	'mail.Charset = "iso-2022-jp"
	'mail.ContentTransferEncoding = "quoted-printable"
	mail.From		= fromEmail
	mail.FromName	= fromName
	mail.silent		= false
	mail.Subject	= subject
	mail.Body		= body
	if contType = 1 then			'Send HTML Email
		mail.ContentType = "text/html"
	end if
	if isArray(toEmail) then		'Send Multiple Emails
		for I = 0 to Ubound(toEmail)
			if len(toEmail(I)) > 0 then
				mail.ClearRecipients()
				mail.AddRecipient toEmail(I)
				if len(pEmailAdminUser) > 0 then
					mail.MailServerUserName = pEmailAdminUser
					mail.MailServerPassword = pEmailAdminPassword
				end if
				mail.Send(pSmtpServer)
			end if
		next
	else							'Send Single Email
		mail.AddRecipient toEmail
		if len(pEmailAdminUser) > 0 then
			mail.MailServerUserName = pEmailAdminUser
			mail.MailServerPassword = pEmailAdminPassword
		end if
		mail.Send(pSmtpServer)
	end if
	set mail = nothing
end Function
 
'CDONTS
'Note : After the "Send" method, the "NewMail" object becomes invalid.
'       We therefore have to create the "NewMail" object for each email.
Function CDONTS(fromName, fromEmail, toEmail, subject, body, contType)
	dim mail,I
	if isArray(toEmail) then		 'Send Multiple Emails
		for I = 0 to Ubound(toEmail)
			if len(toEmail(I)) > 0 then
				Set mail = Server.CreateObject ("CDONTS.NewMail")
				if contType = 1 then 'Send HTML Email
					mail.BodyFormat = 0
					mail.MailFormat = 0
				end if
				mail.Send fromEmail & " (" & fromName & ")", toEmail(I), subject, body
				set mail = nothing
			end if
		next
	else							 'Send Single Email
		Set mail = Server.CreateObject ("CDONTS.NewMail")
		if contType = 1 then		 'Send HTML Email
			mail.BodyFormat = 0
			mail.MailFormat = 0
		end if
		mail.Send fromEmail & " (" & fromName & ")", toEmail, subject, body
		set mail = nothing
	end if
end Function
 
'Persits ASP Email
Function PASPEmail(fromName, fromEmail, toEmail, subject, body, contType)
	dim mail,I
	set mail = server.CreateObject("Persits.MailSender")
	'mail.Charset = "iso-2022-jp"
	'mail.ContentTransferEncoding = "quoted-printable"
	mail.Host		= pSmtpServer 
	mail.From		= fromEmail
	mail.FromName	= fromName
	mail.Subject	= subject
	mail.Body		= body
	if pEmailAdminUser <> "" then
		mail.user = pEmailAdminUser
		mail.password = pEmailAdminPassword
	end if
	if contType = 1 then			'Send HTML Email
		mail.IsHTML = True 
	end if
	if isArray(toEmail) then		'Send Multiple Emails
		for I = 0 to Ubound(toEmail)
			if len(toEmail(I)) > 0 then
				mail.Reset
				mail.AddAddress toEmail(I)
				mail.Send
			end if
		next
	else							'Send Single Email
		mail.AddAddress toEmail
		mail.Send
	end if
	set mail = nothing
end Function
 
'ServerObjects ASPMail
Function SOASPMail(fromName, fromEmail, toEmail, subject, body, contType)
	dim mail,I
	set mail		 = server.CreateObject("SMTPsvg.Mailer")
	mail.RemoteHost	 = pSmtpServer
	mail.FromAddress = fromEmail
	mail.FromName	 = fromName
	mail.Subject	 = subject
	mail.BodyText	 = body
	if contType = 1 then			'Send HTML Email
		mail.ContentType = "text/html"
	end if
	if isArray(toEmail) then		'Send Multiple Emails
		for I = 0 to Ubound(toEmail)
			if len(toEmail(I)) > 0 then
				mail.ClearRecipients
				mail.AddRecipient "", toEmail(I)
				mail.SendMail
			end if
		next
	else							'Send Single Email
		mail.AddRecipient "", toEmail
		mail.SendMail
	end if
	set mail = nothing
end Function
 
'Bamboo SMTP
Function bamboo(fromName, fromEmail, toEmail, subject, body, contType)
	dim mail,I
	set mail      = Server.CreateObject("Bamboo.SMTP") 
	mail.Server   = pSmtpServer
	mail.From     = fromEmail
	mail.FromName = fromName
	mail.Subject  = subject
	mail.Message  = body
	if contType = 1 then			'Send HTML Email
		mail.ContentType = "text/html"
	end if
	if isArray(toEmail) then		'Send Multiple Emails
		for I = 0 to Ubound(toEmail)
			if len(toEmail(I)) > 0 then
				mail.Rcpt = toEmail(I)
				mail.Send 
			end if
		next
	else							'Send Single Email
		mail.Rcpt = toEmail
		mail.Send 
	end if
	set mail      = nothing
end Function
 
'CDOSYS
Function CDOSYS(fromName, fromEmail, toEmail, subject, body, contType)
	dim mail,conf,I
	'on error resume next
	'Configure the server
	Set mail = Server.CreateObject("CDO.Message")
	Set conf = Server.CreateObject("CDO.Configuration")
 
    conf.Fields.Item(cdoSendUsingMethod) = cdoSendUsingPort
	conf.Fields.Item(cdoSMTPServer) = pSmtpServer
	conf.Fields.Item(cdoSMTPConnectionTimeout) = 30
	conf.Fields.Item(cdoSMTPServerPort) = 25
	if pEmailAdminUser <> "" then
		conf.Fields.Item(cdoSMTPAuthenticate) = 1 'cdoBasic clear-text 
		conf.Fields.Item(cdoSendUsername) = pEmailAdminUser 
		conf.Fields.Item(cdoSendPassword) = pEmailAdminPassword
	end if 
	conf.Fields.Update
	
	'Send email
	mail.Configuration = conf
	'mail.BodyPart.Charset = "iso-2022-jp"
	'mail.BodyPart.ContentTransferEncoding = "quoted-printable"
	mail.From	 = replace(fromName,",","") & " <" & fromEmail & ">"
	mail.Subject = subject
	if contType = 1 then			'Send HTML Email
		mail.HTMLBody = body
	else
		mail.TextBody = body
	end if
	if isArray(toEmail) then		'Send Multiple Emails
		for I = 0 to Ubound(toEmail)
			if len(toEmail(I)) > 0 then
				mail.To = toEmail(I)
				on error resume next
				mail.Send
				if err.number <> 0 then
					if instr(Request.ServerVariables("URL"),"Admin")>0 Then
						response.redirect "sysMsg.asp?errMsg=" & server.URLEncode(err.number & ":" & err.description & ": Unable to send email message. Check your store email settings.")
					else
						response.redirect "Default.asp?mainpage=sysMsg&errMsg=" & server.URLEncode(err.number & ":" & err.description & ": Unable to send email message. Check your store email settings.")
					end if
				end if	
			end if
		next
	else							'Send Single Email
		mail.To = toEmail
		on error resume next
		mail.Send
		if err.number <> 0 then
			if instr(Request.ServerVariables("URL"),"Admin")>0 Then
				response.redirect "sysMsg.asp?errMsg=" & server.URLEncode(err.number & ":" & err.description & ": Unable to send email message. Check your store email settings.")
			else
				response.redirect "Default.asp?mainpage=sysMsg&errMsg=" & server.URLEncode(err.number & ":" & err.description & ": Unable to send email message. Check your store email settings.")
			end if
		end if
	end if
	
	'Clean up
	set mail = nothing
	set conf = nothing
 
end Function
%>

Open in new window

0
sdugar
Asked:
sdugar
  • 4
  • 3
1 Solution
 
sunithnairCommented:
You are calling the function like this call sendmail (CustName, pEmailAdmin, emailTo, emailSubject, CustMessage, 0) which will actually use the TextBody option shown in line 215. You need to call the function like this call sendmail (CustName, pEmailAdmin, emailTo, emailSubject, CustMessage, 1)
0
 
sdugarAuthor Commented:
I already tried sendmail (CustName, pEmailAdmin, emailTo, emailSubject, CustMessage, 1)

but its not wrking.

regards,
0
 
sdugarAuthor Commented:
when i tried to see the html matter in browser using " response.write ". Its not showing html content its showing HTML TAGS.

REGARDS
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sunithnairCommented:
Are you encoding your message body using Server.HtmlEncode?
0
 
sdugarAuthor Commented:
no....i have just tried to write a response from database using a variable.
0
 
sunithnairCommented:
Ok so the message in the database may be stored in HtmlEncoded string. Please check the value in your database. You can decode the string Server.HtmlDecode. Try response.write(Server.HtmlDecode(variable))
0
 
sdugarAuthor Commented:
thanks sunith!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now