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

Introduction

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: 5/23/2012 2:15:32 AM
Comment:
Sending email from ASP.NET v2.0 application using SMTp Server
Title: SP   
Name: SP
Date: 4/16/2010 8:31:14 AM
Comment:
SV TELECOM
" soluções para redução de custo de celulares corporativos "

" OFERTA LIBERTY " APROVEITE !!!!!!!!!!!


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

www.svtelecom.com.br

se desejar não receber mais este informativo, envie REMOVER para svtelecom@svtelecom.com.br
(11) 2741-1098
svtelecom@svtelecom.com.br
Title: How to send to a Email Group   
Name: Abdul
Date: 10/1/2009 2:40:05 PM
Comment:
Hello, any body let me know in asp.net 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: 4/16/2009 4:54:21 AM
Comment:
Hello,

I have added email.replyto = new mailaddress("xxx@gmail.com")

Its working perfectly in gmail,yahoo etc.

But in Thunderbird it showing from address as replyto address instead "xxx@gmail.com"

How to solve this issue?

Thanks in advance.
Title: implementing code for email   
Name: sunil
Date: 4/12/2009 10:27:10 PM
Comment:
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="sunil.ss@gmail.com";
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 force.com", TextBox7.Text);
SmtpClient client = new SmtpClient("smtps.gmail.com", googleMailPortNumber);
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials=new System.Net.NetworkCredential(username, password);
client.Send(mail);
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: 4/7/2009 5:53:28 AM
Comment:
how send an sms using vb,net
Title: remove name from emails that are sent   
Name: cathy szomolyai
Date: 2/18/2009 3:35:44 PM
Comment:
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: 11/6/2008 1:13:06 AM
Comment:
There is a very simple way to achieve this.
Please try this and see.
email.From = new MailAddress(MailFrom);

Thanks.
Title: mail is not sending   
Name: avi
Date: 10/21/2008 6:35:57 AM
Comment:
some error occured
Title: Remote Server not available   
Name: George
Date: 9/2/2008 12:01:44 PM
Comment:
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: 8/6/2008 3:07:32 AM
Comment:
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: 6/24/2008 3:55:23 PM
Comment:
thanks
Title: Domain problem   
Name: konac
Date: 5/20/2008 11:23:28 AM
Comment:
i have a problem. the script only sends emails to domains which reside on my hosting server but not to gmail.com, yahoo.com...please help
Title: smtp settings in web.config   
Name: KarinJ
Date: 5/13/2008 12:47:38 AM
Comment:
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.
Title: EMAIL RECEIVEING IN HTML FORMAT   
Name: rohit Shrivastava
Date: 4/23/2008 1:30:49 AM
Comment:
Hi
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

Thanks
Title: Hi   
Name: Welly
Date: 4/17/2008 11:41:36 PM
Comment:
Can I send email into a POP3 email server using ASP.NET 2.0?
Title: Answere: Working with Email...   
Name: RiZk
Date: 3/31/2008 2:25:12 PM
Comment:
The MailMessage To property is a collection, use Add!
mail.To.Add("email@mymail.com")
Title: Working with Email Using ASP.NET 2.0   
Name: vineeth
Date: 3/24/2008 4:06:55 AM
Comment:
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: 3/20/2008 5:04:24 AM
Comment:
Sending email from ASP.NET v2.0 application using SMTp Server
Title: find   
Name: pallav
Date: 1/30/2008 7:23:01 AM
Comment:
it's gr8t

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

MailMessage mail = new MailMessage();

mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "username@gmail.com";
mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "password";
mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = "465";
mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"]= "True";

mail.From = "asfa@asdf.com";
mail.To = "asfa@asdf.com";

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

SmtpMail.Send(mail);
Title: send emails to group of people   
Name: Malakool
Date: 11/10/2007 1:13:53 AM
Comment:
Hi,

i want to sent emails or newsletter in group wise plz help me for that
Title: Error Sys.WebForm.PageRequestManagerServerErrorException   
Name: kumaraatish
Date: 7/17/2007 6:32:02 AM
Comment:
Hi, I am using c# asp.net 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..
Sys.WebForm.PageRequestManagerServerErrorException
How do i do this? what is the flaw?
Title: Very good   
Name: Yahsaar
Date: 7/15/2007 2:39:58 PM
Comment:
very very nice
Title: hi   
Name: sumanth
Date: 7/4/2007 1:57:35 AM
Comment:
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: 6/24/2007 1:37:41 PM
Comment:
very clear step by step directions.... could have done a better job myself
Title: clairest abicale im reed   
Name: Raja
Date: 6/19/2007 1:30:19 PM
Comment:
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: 6/10/2007 9:19:33 AM
Comment:
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 = "mohanraja1983@gmail.com"
message.To = toAddress
message.Subject = TextBox1.Text
message.Body = TextBox2.Text
message.Priority = MailPriority.High
message.BodyFormat = MailFormat.Html
'SmtpMail.SmtpServer = "192.168.1.254"
SmtpMail.SmtpServer = "127.0.0.1"
SmtpMail.Send(message)
Title: how to change the oulook address   
Name: sudheer
Date: 6/7/2007 7:50:17 AM
Comment:
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 boddapati.sudheer@gmail.com
Title: Great explain   
Name: Cemal Safi
Date: 5/29/2007 4:32:38 AM
Comment:
Avcikahvesi.Com - That is the greatest explain i have ever seen. thank you for everything :)
Title: Error msg   
Name: Udana
Date: 5/7/2007 2:53:36 AM
Comment:
whan i run the app i get a msg as" smtpEception was unhandled by user code" (im new to this asp.net)... have u got anything to say
Title: perferct way to make it understood   
Name: Renu singal
Date: 4/5/2007 4:15:39 AM
Comment:
thnaks , for amking my concept clear abt this .
Title: Great Article   
Name: SuperbDotNetDeveloper
Date: 3/28/2007 7:46:14 AM
Comment:
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.

Thanks

MFB
Title: to hardcode or not to hardcode   
Name: McGuire
Date: 2/5/2007 2:09:58 PM
Comment:
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
msg.To.Add(strEmail)
Title: How To send Group mail   
Name: Dhaksh
Date: 1/29/2007 11:53:38 PM
Comment:
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 dhaksh@gmail.com.
Title: Excellant explaination. thanks. but i cant sent to yahoo id   
Name: Gowsi
Date: 1/22/2007 2:09:53 AM
Comment:
Excellant explaination. thanks. but i cant sent to yahoo id.
can u tell me why. plz send response to this id: gowsi32@yahoo.co.in
Title: Setting email.From   
Name: Curt
Date: 1/9/2007 7:08:22 PM
Comment:
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 asp.net 2.0 version   
Name: DotNetSpace
Date: 12/5/2006 9:15:14 PM
Comment:
Very simple example on how to send emails using asp.net 2.0 with C#.

http://www.dotnetspace.com/articles/general-articles/sending-emails.html

the code example works for asp.net 2.0 version.
Title: Got problem when sending email to Yahoo or Gmail!   
Name: Ky Thanh Pham
Date: 11/4/2006 12:26:53 PM
Comment:
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: 10/2/2006 4:17:50 AM
Comment:
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: 9/11/2006 2:36:23 AM
Comment:
This article is very simple to read and easy to understand how to send e-mail with advanced features using asp.net 2.0

Great

Thanks
Soft Tester[Always have mentality for testing any kind of software instead of using it]
Title: Asp.net 2.0: i can not send mail via google pop3 account   
Name: hoangchau
Date: 9/11/2006 1:06:04 AM
Comment:
In asp.net 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 asp.net 1.1:
Dim objMail As New MailMessage
....
objMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = [newport]
objMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
....
Title: No need for all that code in section 3   
Name: Rob Teegarden
Date: 9/9/2006 11:14:35 AM
Comment:
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: 9/8/2006 9:03:14 AM
Comment:
Really useful
Title: article feedback did not include the url   
Name: DotNetManiac
Date: 9/7/2006 6:40:31 AM
Comment:
so i put it in the comments...

http://www.dotnetmaniac.com/ArticleViewer.aspx?Key={fc57945a-a859-4015-88d6-16938b829b74}
Title: Sending mail with windows forms 2.0   
Name: DotNetManiac
Date: 9/7/2006 6:39:26 AM
Comment:
great article for beginners sending mail with asp.net. I have an example using windows forms at this url.
Title: Simple and good Article for sending mail   
Name: Vikram Lakhotia
Date: 9/7/2006 4:08:20 AM
Comment:
This is good and simple article for sending mail. But we can do many more complicated stuff in asp.net 2.0 with the smpt namespace

Product Spotlight
Product Spotlight 





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


©Copyright 1998-2014 ASPAlliance.com  |  Page Processed at 7/28/2014 12:22:48 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search