473,792 Members | 2,796 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't send html email message with asp.net

Hello to everyone,
Does anybody know how to send html formatted messages with asp.net?
I tried to send such messages with the code below but the content type is wrong.
The content type is multi-part and not html/text as expected.

The code i use is:
mailmsg.To = "XX*@XXXX.c om"
mailmsg.Subject = "some subject string"
mailmsg.Body = <-- an html format body -->
mailmsg.From = "XX*@XXXX.c om"
mailmsg.BodyFor mat = MailFormat.Html
Try
SmtpMail.SmtpSe rver = "127.0.0.1"
SmtpMail.Send(m ailmsg)
Catch exc As Exception
Response.Write( exc.Message)
Response.End()
End Try
Nov 18 '05 #1
5 2324
A new FAQ has just been posted with lots of info that might help:

http://www.systemwebmail.com/

"Yossi Naggar" <na****@netvisi on.net.il> wrote in message
news:d3******** *************** ***@posting.goo gle.com...
Hello to everyone,
Does anybody know how to send html formatted messages with asp.net?
I tried to send such messages with the code below but the content type is
wrong.
The content type is multi-part and not html/text as expected.

The code i use is:
mailmsg.To = "XX*@XXXX.c om"
mailmsg.Subject = "some subject string"
mailmsg.Body = <-- an html format body -->
mailmsg.From = "XX*@XXXX.c om"
mailmsg.BodyFor mat = MailFormat.Html
Try
SmtpMail.SmtpSe rver = "127.0.0.1"
SmtpMail.Send(m ailmsg)
Catch exc As Exception
Response.Write( exc.Message)
Response.End()
End Try


Nov 18 '05 #2
Here is what works for me:

Dim MM As New System.Web.Mail .MailMessage
Dim S As String
MM.From = Me.txtFromEmail .Text
MM.To = Me.txtToEmail.T ext
MM.Subject = Me.txtSubject.T ext
MM.BodyFormat = System.Web.Mail .MailFormat.Htm l
S = "<html><hea d></head><body>"
S = S & "<p></p>"
S = S & Whatever HTML code you need to put for your message
S = S & "</body></html>"
MM.Body = S
System.Web.Mail .SmtpMail.SmtpS erver = Your SMPT server name (the
name of your computer if you are testing on localhost)
System.Web.Mail .SmtpMail.Send( MM)

"Yossi Naggar" <na****@netvisi on.net.il> wrote in message
news:d3******** *************** ***@posting.goo gle.com...
Hello to everyone,
Does anybody know how to send html formatted messages with asp.net?
I tried to send such messages with the code below but the content type is wrong. The content type is multi-part and not html/text as expected.

The code i use is:
mailmsg.To = "XX*@XXXX.c om"
mailmsg.Subject = "some subject string"
mailmsg.Body = <-- an html format body -->
mailmsg.From = "XX*@XXXX.c om"
mailmsg.BodyFor mat = MailFormat.Html
Try
SmtpMail.SmtpSe rver = "127.0.0.1"
SmtpMail.Send(m ailmsg)
Catch exc As Exception
Response.Write( exc.Message)
Response.End()
End Try

Nov 18 '05 #3
Well, your code sure works.
But i encountered another problem: the body of the message (which is
ofcourse an HTML code) is the value of a textarea in my web
application.

If i set the MM.Body as you have done then it's alright, but if i set
MM.Body to be the value of the textarea then i get the message in the
wrong format.

What do you think is the problem?

"William LaMartin" <la******@tampa bay.rr.com> wrote in message news:<eP******* *******@TK2MSFT NGP09.phx.gbl>. ..
Here is what works for me:

Dim MM As New System.Web.Mail .MailMessage
Dim S As String
MM.From = Me.txtFromEmail .Text
MM.To = Me.txtToEmail.T ext
MM.Subject = Me.txtSubject.T ext
MM.BodyFormat = System.Web.Mail .MailFormat.Htm l
S = "<html><hea d></head><body>"
S = S & "<p></p>"
S = S & Whatever HTML code you need to put for your message
S = S & "</body></html>"
MM.Body = S
System.Web.Mail .SmtpMail.SmtpS erver = Your SMPT server name (the
name of your computer if you are testing on localhost)
System.Web.Mail .SmtpMail.Send( MM)

"Yossi Naggar" <na****@netvisi on.net.il> wrote in message
news:d3******** *************** ***@posting.goo gle.com...
Hello to everyone,
Does anybody know how to send html formatted messages with asp.net?
I tried to send such messages with the code below but the content type is

wrong.
The content type is multi-part and not html/text as expected.

The code i use is:
mailmsg.To = "XX*@XXXX.c om"
mailmsg.Subject = "some subject string"
mailmsg.Body = <-- an html format body -->
mailmsg.From = "XX*@XXXX.c om"
mailmsg.BodyFor mat = MailFormat.Html
Try
SmtpMail.SmtpSe rver = "127.0.0.1"
SmtpMail.Send(m ailmsg)
Catch exc As Exception
Response.Write( exc.Message)
Response.End()
End Try

Nov 18 '05 #4
Well, i am glad to tell you that the problem solved:

The body of my message was set to the value of a textarea control.
The reason why i couldn't see html was the replacement of the
characters "<", ">", " " etc. with the special characters: "&lt;",
"&gt;", "&nbsp;" and so on.

It seems that if you write an HTML code in textarea or other control,
then the .NET replaces the characters: "<", "<", etc. with the special
characteres above.

In order to get rid of those special characters you can do:

MM.Body = replace(MM.Body , "&lt;", "<")
MM.Body = replace(MM.Body , "&gt;", ">")
.....

and so on

BUT: if you want to solve the problem with even more simple way you
can do:

MM.Body = Me.Textarea1.Va lue.InnerText

This works just fine.
"William LaMartin" <la******@tampa bay.rr.com> wrote in message news:<eP******* *******@TK2MSFT NGP09.phx.gbl>. ..
Here is what works for me:

Dim MM As New System.Web.Mail .MailMessage
Dim S As String
MM.From = Me.txtFromEmail .Text
MM.To = Me.txtToEmail.T ext
MM.Subject = Me.txtSubject.T ext
MM.BodyFormat = System.Web.Mail .MailFormat.Htm l
S = "<html><hea d></head><body>"
S = S & "<p></p>"
S = S & Whatever HTML code you need to put for your message
S = S & "</body></html>"
MM.Body = S
System.Web.Mail .SmtpMail.SmtpS erver = Your SMPT server name (the
name of your computer if you are testing on localhost)
System.Web.Mail .SmtpMail.Send( MM)

"Yossi Naggar" <na****@netvisi on.net.il> wrote in message
news:d3******** *************** ***@posting.goo gle.com...
Hello to everyone,
Does anybody know how to send html formatted messages with asp.net?
I tried to send such messages with the code below but the content type is

wrong.
The content type is multi-part and not html/text as expected.

The code i use is:
mailmsg.To = "XX*@XXXX.c om"
mailmsg.Subject = "some subject string"
mailmsg.Body = <-- an html format body -->
mailmsg.From = "XX*@XXXX.c om"
mailmsg.BodyFor mat = MailFormat.Html
Try
SmtpMail.SmtpSe rver = "127.0.0.1"
SmtpMail.Send(m ailmsg)
Catch exc As Exception
Response.Write( exc.Message)
Response.End()
End Try

Nov 18 '05 #5
use Server.HTMLEnco de to restore your textarea entry or use the
VaildateRequest =false Page attribute. This behavior is new in .NET 1.1 due
to security considerations. Hope this helps.
--
Peter O'Reilly
Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
3729
by: tabonni | last post by:
Hi I try to grab the checked files from HTML page and then send those PDF files as attachments. It can just send email, there are no PDF files attached. Can anybody point out my error? My idea is: When people check the check boxes in HTML page for the PDF files, it will transfer the files' name to ASP page. Then, it will attach it in the email.
6
11189
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I will include the code I originally used. I understand I should switch from CDONTS to CDO mail but after several sttempts I am finding a very hard time getting the new CDO mail to work properly. Any assistance with this would be greatly...
1
2173
by: Miguel Dias Moura | last post by:
Hello, Can you help me out in making this work? What I want is as simple as sending form values to an email. The code I am using is the following:
1
1077
by: Miguel Dias Moura | last post by:
Hello, Can you help me out in making this work? What I want is as simple as sending form values to an email. The code I am using is the following:
6
4904
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
11
26642
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package and PEAR is in c:\wamp\php\pear I modified php.ini in the c:\wamp\php directory to reflect the actual path, but even stopping and restarting my server shows the c: \php5\pear path. I can't change it no matter what I do I also tried the...
10
2762
by: sufian | last post by:
I am new to the world of PHP. Below is my simple PHP file "invite.php" with a form having an image send button (I have to use the image send button because it is the requirement, may be this is causing problem!): <html> <head><title>Form</title> </head> <body> <script language="javascript" src="validation.js"></script> <form action="submit.php" method="POST"> <table border ="0" align="center" cellpadding="9"...
6
5938
by: =?Utf-8?B?TMOhemFybw==?= | last post by:
Hi everyone I've a simple ASP.NET Page that send a email using smtclient. The server is a Exchange and use my credentials to autentificated. The problem is that the send mail appear in the junk email folder. Any idea. Thanks
7
3485
by: redblue | last post by:
Hi all, i am new in php, I looked lots of example from Forum and tried online server but its nt work at all, i know i may be doing great mistake to sending HTML mail. last time i tried this code beloo, pls give me idea what is the erroe and its say "Mail Failed' <?php $to = 'example@test.com'; $subject = 'Test HTML email'; $random_hash = md5(date('r', time())); $headers = "From: webmaster@example.com\r\nReply-To:...
1
3601
by: Michael31277 | last post by:
I keep getting this error on my form code, but only when I keep the MailNewObj.Send in the code, so I know it is this... I get the 500 INTERNAL ERROR message.. I tried shutting off "friendly messages" in IE, but it still winds up with the same message... I am publishing to GoDaddy and the GoDaddy server is ASP/LINUX since I wanted a combination of both... GoDaddy mentioned I should add the following lines, somewhere in my code:OUTGOING SERVER =...
0
9670
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10159
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.