Working with Email Using ASP.NET 2.0
page 1 of 6
Published: 01 Sep 2006
Unedited - Community Contributed
In this article Jason examines the various aspects involved with sending of emails using ASP.NET 2.0.
by Jason N. Gaylord
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 55060/ 60


In ASP.NET 1.x sending email was fairly simple.  The only issue was that there were different ways to send email depending on whether the application was web or windows based.  Windows developers used MAPI to send emails using an email client like Outlook.  Web developers used CDOSYS to send rich emails.  Microsoft realized that a change was warranted.  In ASP.NET 2.0 Microsoft released a new set of classes to handle email.  The only issue is that to many developers, sending email became much more complex.  Within this article, we will walk through the changes to the web.config file, the new classes that are available and how to send email using the new MailMessage class.

View Entire Article

User Comments

Title: Sending email from ASP.NET v2.0 application using SMTp Server   
Name: Rajaraman
Date: 2012-05-23 2:15:32 AM
Sending email from ASP.NET v2.0 application using SMTp Server
Title: SP   
Name: SP
Date: 2010-04-16 8:31:14 AM
" soluções para redução de custo de celulares corporativos "


Fale Ilimitado com seu grupo e mais 40 milhões de celulares no BRASIL por apenas R$ 19,00.

Temos Pós venda ( auxilia seu atendimento e a manutenção do seu contrato junto a Operadora )

Isenção para deslocamento em Roaming

Diminua o custo da conta de celular de sua empresa em mais de 30%

acesse agora e solicite maiores informações através do nosso site

se desejar não receber mais este informativo, envie REMOVER para
(11) 2741-1098
Title: How to send to a Email Group   
Name: Abdul
Date: 2009-10-01 2:40:05 PM
Hello, any body let me know in 1.1 , how do you send email to a group name. The group is logical email list. can change an point of time and which is managed in Outlook or Lotus notes etc..
Iam using SmtpMail and send()
Title: email.ReplyTo   
Name: Fathima
Date: 2009-04-16 4:54:21 AM

I have added email.replyto = new mailaddress("")

Its working perfectly in gmail,yahoo etc.

But in Thunderbird it showing from address as replyto address instead ""

How to solve this issue?

Thanks in advance.
Title: implementing code for email   
Name: sunil
Date: 2009-04-12 10:27:10 PM
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;

public partial class Student_invite : System.Web.UI.Page
const int googleMailPortNumber = 587;
const string username="";
const string password = "9416717917";
protected void Page_Load(object sender, EventArgs e)

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)

MailMessage mail = new MailMessage(username, TextBox2.Text, "Invitation for e-future", TextBox7.Text);
SmtpClient client = new SmtpClient("", googleMailPortNumber);
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials=new System.Net.NetworkCredential(username, password);
Label3.Text = "The invitation has been sent.";
this is my code to send invitation for using my website

but when i run it then a runtime error occurs: mail sending failure

Please help me to remove this error
Title: dd   
Name: dd
Date: 2009-04-07 5:53:28 AM
how send an sms using vb,net
Title: remove name from emails that are sent   
Name: cathy szomolyai
Date: 2009-02-18 3:35:44 PM
i want to remove my name from appearing on emails I am sending. how do i do this? where do i go to remove this information?
Title: Reply to "Setting email.From" From Curt   
Name: Sachih Chandrasiri
Date: 2008-11-06 1:13:06 AM
There is a very simple way to achieve this.
Please try this and see.
email.From = new MailAddress(MailFrom);

Title: mail is not sending   
Name: avi
Date: 2008-10-21 6:35:57 AM
some error occured
Title: Remote Server not available   
Name: George
Date: 2008-09-02 12:01:44 PM
Good suggestions and thanks.... But I am getting an error message that the remote server is not available when I try send the mail from Windows 2K server SP4.....
Title: Hello   
Name: Deepa
Date: 2008-08-06 3:07:32 AM
i try the code in ASP.NET web form. It sends mail out but did not reach in inbox of given recipients address
Title: Excellent Article   
Name: Rick Gabrielli
Date: 2008-06-24 3:55:23 PM
Title: Domain problem   
Name: konac
Date: 2008-05-20 11:23:28 AM
i have a problem. the script only sends emails to domains which reside on my hosting server but not to, help
Title: smtp settings in web.config   
Name: KarinJ
Date: 2008-05-13 12:47:38 AM
Thank you for showing the code on how to get the SMTP stuff from web.config. Most articles don't include that. I have my 'From' email address in the mailSettings section and was stuck on how to retrieve it until I read this article. Thanks again! Karin.
Name: rohit Shrivastava
Date: 2008-04-23 1:30:49 AM
Can any one tell me how i can receive and view the mail which is in HTML format..
I am not-concern in sending HTML mail .. I am concern in only receiveing the HTML format mail.
Can any one tell me how i can do this. its urgent

Title: Hi   
Name: Welly
Date: 2008-04-17 11:41:36 PM
Can I send email into a POP3 email server using ASP.NET 2.0?
Title: Answere: Working with Email...   
Name: RiZk
Date: 2008-03-31 2:25:12 PM
The MailMessage To property is a collection, use Add!
Title: Working with Email Using ASP.NET 2.0   
Name: vineeth
Date: 2008-03-24 4:06:55 AM
how to send more than one mail at a time?
Title: Sending email from ASP.NET v2.0 application using SMTp Server   
Name: Rajaraman
Date: 2008-03-20 5:04:24 AM
Sending email from ASP.NET v2.0 application using SMTp Server
Title: find   
Name: pallav
Date: 2008-01-30 7:23:01 AM
it's gr8t

Title: Sending email from ASP.NET v1.1 application using Gmail SMTp Server   
Name: Sethupathy
Date: 2008-01-11 4:42:14 AM
Sending email from ASP.NET v1.1 using Gmail SMTP Server:

MailMessage mail = new MailMessage();

mail.Fields[""] = 1;
mail.Fields[""] = "";
mail.Fields[""] = "password";
mail.Fields[""] = "465";
mail.Fields[""]= "True";

mail.From = "";
mail.To = "";

mail.Subject = "Sample" mail.BodyFormat = MailFormat.Html;
mail.Body = "Sample"
SmtpMail.SmtpServer = "";

Title: send emails to group of people   
Name: Malakool
Date: 2007-11-10 1:13:53 AM

i want to sent emails or newsletter in group wise plz help me for that
Title: Error Sys.WebForm.PageRequestManagerServerErrorException   
Name: kumaraatish
Date: 2007-07-17 6:32:02 AM
Hi, I am using c# 2.0 for this purpose...
Now i have a problem. my code mails the specific email address only when i am in debud mode....that is if i upload the site on a server, it gives an error..
How do i do this? what is the flaw?
Title: Very good   
Name: Yahsaar
Date: 2007-07-15 2:39:58 PM
very very nice
Title: hi   
Name: sumanth
Date: 2007-07-04 1:57:35 AM
can you do this by using C# codes coz now a days almost all companies are using C# languages not only this article. All articles from ASP ALLIANCE
Title: tovario solutions   
Name: thomas freeman
Date: 2007-06-24 1:37:41 PM
very clear step by step directions.... could have done a better job myself
Title: clairest abicale im reed   
Name: Raja
Date: 2007-06-19 1:30:19 PM
Thankjous for mooking these abicale vevy clear. I overstand it weal. Goud Wok!!
Title: how to avoid the messages to be spam   
Name: Mohan Raja
Date: 2007-06-10 9:19:33 AM
Hai plz help me, I am sending Bulk Mail using asp.net1.1. when i send the single message to all receiptants, the messages are stored in bulk folder in yahoo domain. Other id's are not received the message. Plz help me how to rectify it...
My code is...
message.From = ""
message.To = toAddress
message.Subject = TextBox1.Text
message.Body = TextBox2.Text
message.Priority = MailPriority.High
message.BodyFormat = MailFormat.Html
'SmtpMail.SmtpServer = ""
SmtpMail.SmtpServer = ""
Title: how to change the oulook address   
Name: sudheer
Date: 2007-06-07 7:50:17 AM
actually this is good article.this is very useful to me.
but i have some other quereys about this article.
1) i am placed one button control and one one textbox control.if i want change the outlook address at that time i am place the email address into the textbox whenever i am click the button that time the outlook To address is dynamically change how is it possible please send the code for this problem into
Title: Great explain   
Name: Cemal Safi
Date: 2007-05-29 4:32:38 AM
Avcikahvesi.Com - That is the greatest explain i have ever seen. thank you for everything :)
Title: Error msg   
Name: Udana
Date: 2007-05-07 2:53:36 AM
whan i run the app i get a msg as" smtpEception was unhandled by user code" (im new to this have u got anything to say
Title: perferct way to make it understood   
Name: Renu singal
Date: 2007-04-05 4:15:39 AM
thnaks , for amking my concept clear abt this .
Title: Great Article   
Name: SuperbDotNetDeveloper
Date: 2007-03-28 7:46:14 AM
Hi Jason

Finally a decent article were someone actually knows what they are on about!
I’m a classic ASP developer so still quite new to the ASP.NET technology and I must say “I’m really enjoying ASP.Net”. So for this sending mail with ASP.NET has been really confusing because in ASP we used CDONTS.NewMail (yeah I know that’s really old school). So yeah thanks, the article has been very helpful.


Title: to hardcode or not to hardcode   
Name: McGuire
Date: 2007-02-05 2:09:58 PM
Curt - to not have to hardcode the email address create a variable to capture the email address. for example:
Dim strEmail As String = txtEmail.Text
Title: How To send Group mail   
Name: Dhaksh
Date: 2007-01-29 11:53:38 PM
How to Send a Group mail for example yahoo groups like that.
I want to send a Group mail using outlook can anyone give me a suggestion.Please Reply me at
Title: Excellant explaination. thanks. but i cant sent to yahoo id   
Name: Gowsi
Date: 2007-01-22 2:09:53 AM
Excellant explaination. thanks. but i cant sent to yahoo id.
can u tell me why. plz send response to this id:
Title: Setting email.From   
Name: Curt
Date: 2007-01-09 7:08:22 PM
How do you set the value of email.From without having to hardcode the address?

I've tried the following and it won't accept the email.From = MailFrom:
Dim MailFrom As String
MailFrom = Request.Form.Item("from")
email.From = MailFrom

I've tried the following but it says that the Address property is read-only:
email.From.Address = MailFrom

Any suggestions? I've spend all day today just trying to migrate my ASP code to ASP.NET 2.0 for simply sending emails. This migration has consumed my life. I've never experienced anything more user-hostile than ASP.NET 2.0.
Title: n how to send emails using 2.0 version   
Name: DotNetSpace
Date: 2006-12-05 9:15:14 PM
Very simple example on how to send emails using 2.0 with C#.

the code example works for 2.0 version.
Title: Got problem when sending email to Yahoo or Gmail!   
Name: Ky Thanh Pham
Date: 2006-11-04 12:26:53 PM
I did follow your tutorial but when I send email to Yahoo or Gmail account, I got this error message: Mailbox unavailable. The server response was: Requested action not taken: mailbox unavailable.
Could you tell me why?
Title: Specify more than one SMTP server   
Name: Veselina Radeva
Date: 2006-10-02 4:17:50 AM
Thanks for this article, it works fine for me till now.
I need to specify more than one SMTP server. In case the first one specifies cannot send the email, the second one must be used.

Does anybody have an idea if this is possible?
Title: simple and Clean   
Name: soft tester
Date: 2006-09-11 2:36:23 AM
This article is very simple to read and easy to understand how to send e-mail with advanced features using 2.0


Soft Tester[Always have mentality for testing any kind of software instead of using it]
Title: 2.0: i can not send mail via google pop3 account   
Name: hoangchau
Date: 2006-09-11 1:06:04 AM
In 1.1 i's easy to send mail via gmail account by change port and ssl param, but 2.0 i can't do that.
to change port and ssl pram in 1.1:
Dim objMail As New MailMessage
objMail.Fields("") = [newport]
objMail.Fields("") = True
Title: No need for all that code in section 3   
Name: Rob Teegarden
Date: 2006-09-09 11:14:35 AM
Good article, however for section 3 this is all you need:

Dim client As SmtpClient = New SmtpClient()

The settings will automatically get picked up from the web.config
Title: Good   
Name: vp
Date: 2006-09-08 9:03:14 AM
Really useful
Title: article feedback did not include the url   
Name: DotNetManiac
Date: 2006-09-07 6:40:31 AM
so i put it in the comments...{fc57945a-a859-4015-88d6-16938b829b74}
Title: Sending mail with windows forms 2.0   
Name: DotNetManiac
Date: 2006-09-07 6:39:26 AM
great article for beginners sending mail with I have an example using windows forms at this url.
Title: Simple and good Article for sending mail   
Name: Vikram Lakhotia
Date: 2006-09-07 4:08:20 AM
This is good and simple article for sending mail. But we can do many more complicated stuff in 2.0 with the smpt namespace

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-05-24 10:24:22 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search