Sending SMTP Authenticated E-mail Using ASP.NET 2.0
page 1 of 1
Published: 31 May 2006
Unedited - Community Contributed
In this article, the author examines how to send SMTP authenticated e-mail using ASP.NET 2.0.
by Web Team at ORCS Web
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 105091/ 33


I wrote an article in May 2005 on how to send e-mail via ASP.NET v2.0.  This is a quick follow-up to that article with additional information specifically addressing the issue of SMTP-Authentication against a remote mail server.

Many web hosts now have their servers "locked down" and require a username and password to send e-mail from their servers.  If you have code that uses "localhost" (the SMTP service running on the local machine) then this should not be an issue, but if you have a situation where you need to relay e-mail off a remote mail server that is secured, this article should help you.

The real work is done by the NetworkCredential object.  According to MSDN, this object "provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication."  The benefit of making this a two-step process rather than passing username and password to the .Credentials property of the SmtpClient object is not clear, but that is what is required.

Here is a fully working quick code sample that you can use to get started on your own SMTP-Auth supporting e-mail code.

'Create a new MailMessage object and specify the"From" and "To" addresses
Dim Email As New System.Net.Mail.MailMessage( _
   "", "")
Email.Subject = "test subject"
Email.Body = "this is a test"
Dim mailClient As New System.Net.Mail.SmtpClient()
'This object stores the authentication values
Dim basicAuthenticationInfo As _
   New System.Net.NetworkCredential("username", "password")
'Put your own, or your ISPs, mail server name onthis next line
mailClient.Host = ""
mailClient.UseDefaultCredentials = False
mailClient.Credentials = basicAuthenticationInfo

I would like to thank Marcus McConnell of BV Software and also Brian Linden from CastAds Inc for their tips on how to integrate the SMTP-Authentication process.

User Comments

Title: sdfsf   
Name: sarikonda k suryam raju
Date: 2013-01-07 4:03:52 AM
Title: 567657   
Name: 56756
Date: 2012-11-21 2:12:44 AM
Title: aaa   
Name: dsfd
Date: 2012-08-24 3:44:36 AM
Title: sdcas   
Name: dcsdc
Date: 2012-07-19 2:54:11 PM
Title: auto email in   
Name: wotwow
Date: 2012-07-11 11:19:20 PM
Please teach me how to use smtp in

basically the user sets the date and the time when the email should be send.

send me an email at
Title: mnlk   
Name: gjkhjhjkhjkhj
Date: 2012-06-15 1:48:30 AM
Title: fdsf   
Name: fds
Date: 2012-06-13 2:51:59 AM
Title: mailClient   
Name: mailClient
Date: 2012-06-06 10:04:46 AM
Title: jkjhkj   
Name: kjhkh
Date: 2012-05-29 4:27:19 AM
Title: ,m ,m   
Name: ,m,.m
Date: 2012-05-22 4:30:36 AM
Title: Thanks! Works good   
Name: Haim
Date: 2012-03-15 9:18:07 AM
this is first place i found how to provide credentials without use web.config
Title: C# SMTP MAIL   
Name: saviolan
Date: 2012-02-02 12:34:23 PM
try this simple smtp mail with authentication

Title: Send a mails using   
Name: Ramesh Dharanikota
Date: 2012-01-12 4:55:31 AM
HI ,
I Have one dout in send a mail using . The code is run successfully but i didn't get a mail from domailmailid like ....
and Gmail id is working bt only another mailid is not working. Pleace Help to me

Title: Thank you!!   
Name: Dustin
Date: 2011-02-18 4:46:10 PM
Thank you so much for this code!!!!

We had a Microsoft exchange server 2003 running and for the life of me i couldn't figure out why it was kicking back my emails.

This worked like a charm for passing the authentication for relay.
Title: Help Required   
Name: Anand Dave
Date: 2011-02-17 1:46:06 AM
Hi Code Given Below Run successfully but i don't get email in my mail box Plz Help me oout.....

SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();

MailAddress fromAddress = new MailAddress("From Email Address", "Name");
smtpClient.Host = "";
smtpClient.Credentials = new NetworkCredential("from email address", "pwd");
smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
smtpClient.Port = 465;
message.From = fromAddress;
message.To.Add("my yahoo address");
message.Subject = "Feedback22";
message.IsBodyHtml = false;

message.Body = "Hi Test2 for Email";

lblStatus.Text = "Email successfully sent.";

lblStatus.Text = "Send Email Failed." + ex.Message;
Title: Receiving Mail   
Name: Bibhuti Bhusan Kar
Date: 2010-11-22 8:06:04 AM
How to receive mail from my gmail to werb server mailbox
Title: Imp Code block   
Name: Coder
Date: 2010-10-20 1:31:59 AM
In the above code We also need to use
mailClient.EnableSsl = true;

then the above mentioned Mail sending code will work.
Title: Automatic Mail System   
Name: Ron
Date: 2010-09-17 5:05:40 AM
Hi I have a suggestion to someone of you master programmers. I've gotta create an automatic mail system wich will send a mail to different people (don't worry it's for school) how will I manage to do that?

Tips and suggestions to

thanking you in advance

Title: how to send   
Name: Rajesh
Date: 2010-09-05 9:01:46 AM
hai, anyone explines me about how to send this code via e-mail explain me and send the mail at
Title: Email code in and c #   
Name: Himanshu
Date: 2010-08-03 11:27:53 PM
i have a problem with vb code
so can you give the email code in asp and c#?
pls help me.
My mail id-jo.him1988@GMAIL.COM
Title: exception error   
Name: Sree
Date: 2010-07-24 6:41:43 AM
i used the above code but it shows a "smtpexception failure sending mail" in the line mailclient.send(email)

can u pl help me to sort this out

its really urgent...
Title: exception error   
Name: Sree
Date: 2010-07-24 5:29:33 AM
i used the above code but it shows a "smtpexception" in the line mailclient.send(email)

can u pl help me to sort this out
Title: RE: SMTP configuration?   
Name: Jeremy
Date: 2010-07-21 4:14:56 PM
@Jhon -- see
Title: SMTP configutration?   
Name: Jhon
Date: 2010-07-21 4:02:38 PM
Hi there,
I did the sample here and it doesn't work. I don't know if I have to make some configuration in the SMTP on my local machine...
I got an error about timeout.

I need some help please.
Title: Solved!   
Name: Elvin Meza
Date: 2010-07-03 4:42:26 AM
Thks! you really help me, i've been fighting with this for a while.

great article!
Title: For those who are getting 'Authentication Required' eror   
Name: Uzair Farooq
Date: 2010-06-13 4:11:53 PM
In "username" type first part of your email address i.e if your email address is '' then username will be 'example'
Title: article feedback   
Name: amit kumar
Date: 2010-06-12 6:13:53 AM
Thank you
Title: CC a copy   
Name: Roy, Singapore
Date: 2010-05-13 1:22:07 AM
How to make a cc copy from the sample scripts?
Title: Authentication problem   
Name: Soren Berghall, Sweden
Date: 2010-05-06 11:16:22 AM
Thanks, this solved my problem! Just to transform the code into C#!
Title: Thanks   
Name: MCasanova
Date: 2010-04-14 5:59:56 AM
Thanks, Dominik GOLDSCHMIDT, moving the usedefault credentials did the trick for me
Title: error   
Name: stalin
Date: 2010-04-10 7:29:08 AM
InnerException = {"Unable to connect to the remote server"}

when sent email using my gmail account it show the above error
what can i do for that? please any one said the idea!
Title: Covert code   
Name: Code conversion
Date: 2010-04-09 8:36:00 AM
This below code is using System.web.mail, and now i have to use . plesae tell me what code will be used ??

System.web.mail.MailMessage CustomerMail = new System.web.mail.MailMessage();

CustomerMail.Fields.Add("", strMailServer);

CustomerMail.Fields.Add("", cdoPort);

CustomerMail.Fields.Add("", cdoSendUsing);

CustomerMail.Fields.Add("", cdoAuthentication);
CustomerMail.Fields.Add("", userName);

CustomerMail.Fields.Add("", password);
Title: Mr   
Name: Rob Porto
Date: 2010-03-28 2:52:28 PM
Thanks. Finally a good answer!
Title: kanwal   
Name: kanwalsodha
Date: 2010-03-16 3:44:37 AM
Hello Dear Plz tell me smtp send fail message
Title: nike shoes   
Name: nike shoes
Date: 2010-03-14 10:39:58 PM
It's a very interesting point of view and items that I would like to know more as the interpersonal attitude is something that is not given much information.
Title: set UseDefaultCredentials to false first   
Date: 2010-02-24 4:10:14 AM
You have to set UseDefaultCredentials to false before asigning a new Credentials. Setting UseDefaultCredentials to false after setting Credentials resets Credentials to null.
Title: How to retrieve emails from smtp mail account   
Name: Shruti
Date: 2010-02-23 1:25:47 AM
Can you help me for read emails from smtp email account.
Title: How to pass windows credentials   
Name: Kiran Ayyagari
Date: 2010-01-28 3:50:32 PM
Bellow is the code to pass default windows credentials as authentication for sending mail through your smtp server...

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.Subject = "This is the Subject line";
message.From =new System.Net.Mail.MailAddress("");
message.Body = "This is the message body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();

smtp.Host = "your host server";
smtp.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
Title: how to solve operational time out problem   
Name: Amir
Date: 2010-01-28 4:19:16 AM
i got a problem when i send a mail through asp dot net "operational time out" plz help it nessesery to istall iis to our system on which i send a mail
Title: That is what i'm looking 4!   
Name: safa
Date: 2010-01-14 6:51:22 AM
wow thanks man!! that really helped me! ,, but i wish if i could send HTML emails
Title: Forgot your password connect to be sent in email of users   
Name: Hi again
Date: 2010-01-05 7:46:47 PM
Hi again,

I just saw a video from site and they build an application with login control and the link when users forgot they password.They configured the smtp in application of administration tool and then when they looked on their email they had a password. I think they made a connection with exchange server 2003. Does anybody has any ideas about that will be helpful?. You can write me here:

Thanks in advanced !
Title: Connect with server or send the forgot password in email   
Name: naim
Date: 2010-01-05 7:35:57 PM
Hi guys,

I want in my website in ASP.NET when users forgot password to send it in their email. Does anybody have any idea about that?. It will be good help!

Title: Sending Email Without any Mail Client And CDOS   
Name: Sadashiv Palde
Date: 2009-12-16 2:39:05 AM
please let me know the code, how to send a mail without using mail client, CDOS &CDONTS in .html
Title: sending email   
Name: Alok
Date: 2009-11-19 2:20:56 AM
Following error show please check out:
"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"
I am using emailsend facilities on particular website.
Title: check this out   
Name: Anand
Date: 2009-11-18 2:44:30 PM
check this out!C878CA0BAA85841F!157.entry
Title: Automatic Sending E-mail   
Name: Jaime Corte Real
Date: 2009-10-30 7:43:30 AM
Sridhar, use the scheduler task.
Title: sending mail   
Name: sridhar
Date: 2009-10-04 9:11:06 AM
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

i got this problem please tellme how to send
Title: Automatic Sending E-mail   
Name: Sridhar
Date: 2009-09-07 12:44:48 AM
the above code is good. I need to send mails automatically everyday.How can i add windows services.
Title: sending Mail   
Name: Quest
Date: 2009-08-28 5:38:23 AM
good one which is useful to me

Title: send msg with defualt credential in   
Name: sanjay
Date: 2009-08-10 8:50:13 AM
please help me how send send email msg with defualt credential in
Title: Jojo   
Name: jojo
Date: 2009-07-29 3:01:49 AM
Thanks for this
It worked for me
Title: Web Design Company   
Name: Software Company
Date: 2009-07-22 12:54:05 AM
Nice article.
Title: mr   
Name: finder
Date: 2009-07-12 3:48:23 PM
Title: Sending mail Using Guest Account   
Name: Anubhava Dimri
Date: 2009-07-11 12:45:00 AM
Hi All,
I am sending mail by using Administrator and Standard account it works properly.
But when i try to send mail using guest account it generates following errror.

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. v32sm3231164wah.13

If u have any solution for this issue.
Title: Problem with code.   
Name: Almiro Alves
Date: 2009-07-09 10:21:35 AM
I received the following error when used this code:

System.Exception: Mailbox name not allowed. The server response was: Sorry, that domain isn't in my list of allowed rcpthosts. ---> System.Net.Mail.SmtpFailedRecipientException: Mailbox name not allowed. The server response was: Sorry, that domain isn't in my list of allowed rcpthosts.
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)

I'm using this code:

MailMessage msg = new MailMessage();
msg.From = new MailAddress("");
msg.To.Add(new MailAddress(""));
msg.Subject = "Teste de envio";
msg.Body = "Testando o envio de e-mail através de um WebService.";
msg.IsBodyHtml = true;

SmtpPermission x = new SmtpPermission(SmtpAccess.ConnectToUnrestrictedPort);

SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = false;
smtp.Host = "";
smtp.Port = 80;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("almiro.alves", "******", "");

Anyboy help me please for this problem?

Title: Send Mail Error!   
Name: praveen
Date: 2009-07-09 6:02:58 AM
pls help me when i send a message it shows "Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed".

pls Reply.
Title: Sending mail For Hotmail   
Name: Anubhava Dimri
Date: 2009-05-30 2:46:16 AM
Hello All,
I have generating one issue regarding to sending mail by hotmail.
Title: something difference   
Name: gogoahead
Date: 2009-05-19 12:38:51 PM
my code works fine,and like this:
MailMessage mm = new MailMessage();
mm.From = new MailAddress("");
mm.To.Add(new MailAddress(""));
mm.Subject = "hi";
mm.Body = "hi";
mm.IsBodyHtml = false;
SmtpClient sc = new SmtpClient();
sc.Host = "";
sc.Port = 587;
sc.Credentials = new NetworkCredential("", "password");
sc.EnableSsl = true;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
the main code works fine ,but when i add the line "sc.UseDefaultCredentials =false;" like the article's throw the exception and something like "the server response was XXXX".so just forget about the "sc.UseDefaultCredentials =false;" i don't known why this happen? but for the success delivery of email.maybe you should delete the code line "mailClient.UseDefaultCredentials = False"
Title: "From email" different   
Name: Dipsa
Date: 2009-04-06 2:40:48 AM
the code is works fine. but instead of From email which we have set it shows smtp mail server account. how to solve this? how the actual From address will be shown in email? please reply.
Title: Thanks   
Date: 2009-03-31 5:39:23 AM
thanks for the code.

It worked for me.
Title: Operation Time out error.   
Name: Manjusha
Date: 2009-02-27 6:17:26 AM
My mail ID is
Title: The operation has timed out.   
Name: Manjusha
Date: 2009-02-27 6:15:14 AM
ArrayList items = new ArrayList();

FileStream EmpList = new FileStream(Application.StartupPath +WindowsApplication1.Properties.Settings.Default.EmailFile.ToString() , FileMode.OpenOrCreate, FileAccess.Read);
FileStream Template = new FileStream(Application.StartupPath + WindowsApplication1.Properties.Settings.Default.TemplateFile.ToString(), FileMode.OpenOrCreate, FileAccess.Read);

StreamReader EmpListReader = new StreamReader(EmpList);
StreamReader TemplateReader = new StreamReader(Template);

string EmpInfo, mailbody;
mailbody = TemplateReader.ReadToEnd(); //Assigning template file to the string
String customizemail;
int NoOfEmp = 0;

while ((EmpInfo = EmpListReader.ReadLine()) != null)

string[] EmpInfoItems = EmpInfo.Split(',');

for (int i = 0; i < EmpInfoItems.Length; i++)


DateTime date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
string strdate = date.ToString("D");

// Replacing "Name" by employee name in template
//customizemail = mailbody.Replace("&lt;Name&gt;", EmpInfoItems[0].ToString());
customizemail = mailbody.Replace("{DATE}", strdate);

String emailID = EmpInfoItems[i].ToString();

if (emailID.Contains("@"))
NoOfEmp = NoOfEmp + 1;
MailAddress to = new MailAddress(emailID);
Title: "From email " is different   
Name: rahel
Date: 2009-02-23 5:23:22 PM
thanks for the code is works perfectly but the only problem is instead of from email it shows my smtp mail server account which is ( How can I make it to appear an email from a textbox for the from email part????
Title: Extra fix for GMAIL send   
Name: John
Date: 2009-02-20 5:24:11 AM
if you are sending from gmail and get a Must issue a STARTTLS command first. Error the fix for me was adding

mailClient.EnableSsl = True
Title: Still having the issue   
Name: Nallamani
Date: 2009-02-17 5:21:01 AM
I am not able to send the mail with the NetworkCredential object......I am getting the following error:
System.Net.Mail.SmtpException: Failure sending mail. ---> System.FormatException: Invalid length for a Base-64 char array. at System.Convert.FromBase64String(String s) at System.Net.NTAuthentication.GetOutgoingBlob(String incomingBlob) at System.Net.Mail.SmtpNtlmAuthenticationModule.Authenticate(String challenge, NetworkCredential credential, Object sessionCookie) at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at Email.Send() at Radiotag.forgotpassword.fnsendmail() at Radiotag.forgotpassword.fnsubmit()
Title: Thanks Man   
Name: Mick
Date: 2009-02-16 5:55:08 PM
Perfect mate. Bailed me out of trouble. Now it makes sense
Title: Almost there   
Name: Martin
Date: 2009-02-10 12:25:05 PM
Great article, thanks. I'm still getting the "5.7.1 Client was not authenticated". I have tested the connection to the SMTP server using telnet and sent a mail using the same credentials as in my ASPX file. However when connecting via telnet, the username and password have to be base64 encoded. Any ideas appreciated.
Title: Sending SMTP Authenticated E-mail Using ASP.NET 2.0   
Name: Dan Heath
Date: 2009-02-04 8:31:03 PM
Thank you, exactly what I needed.
Title: Good Article   
Name: Thomas
Date: 2008-12-16 2:19:59 AM
This is good article.For gmail authentication chech
Title: great thanks   
Name: andrew
Date: 2008-11-22 4:49:06 PM
great code thanks.

for those who it doesnt work for - check it plugged in (i.e don't forget the mail namespace)
Title: send mail   
Name: anna
Date: 2008-11-11 12:42:06 AM
plz help me....
urgent plz give me a code for send a mail using SMTP
Title: SMTP porblem   
Name: chetan
Date: 2008-10-15 2:35:24 AM
My mail also sending fail gives error "Mailbox unavailable. The server response was: Authentication is required for relay" but i use proper domain name and password
Please help
Title: worst   
Name: radhika
Date: 2008-10-06 7:26:26 AM
my email is sending failed.becuse of smtp
Title: Useless   
Name: Shefali
Date: 2008-09-19 7:42:49 AM
Hi.I used this code but its not solved my problem.My problem is SMTP is not installed on server side.My mail sending failed.
Title: SMTP   
Name: Yogesh Trivedi
Date: 2008-09-18 6:27:51 AM
Please send me the Code to receive the Mail on my page and also code to receive Delivery Reports. Please help me .........
Title: gmail smtp   
Name: Rahul Anand
Date: 2008-09-15 11:46:02 PM
Please send me the Code to receive the Mail on my page and also code to receive Delivery Reports. Please help me
Title: Email only comes from Credential user   
Name: Russ
Date: 2008-09-08 12:44:21 PM
I am using code just like this and it has always worked. Using gmail, ssl, etc.. the issue is that the emails ALWAYS come from the user I am using in the credentials, which is generic, and not the email address I add in the "FROM" portion. Anyone had this happen before? Thanks!

Title: where is delivery reports for sending mail   
Name: sasikumar
Date: 2008-09-05 9:57:07 AM
i use smtpsend mail option .. i send perfact but not recived delivery reports is possible that one ?
Title: Thanks a Lot   
Name: Samuel Rajan
Date: 2008-09-04 8:54:01 AM
Thanks a lot, earlier from local host, mails use to get into spam but now it is not a spam.
Thank you once again!

With Regards
Samuel Rajan
Title: SMTP Mail delivery on time& date   
Name: Ashwin
Date: 2008-09-04 4:14:13 AM
I would like to ask u about,
how to send an email at a particular time and date.
when iam not available at that time near desktop.
It is like this, I want to send a mail by setting a time previously so that that mail shud b sent at that paricular time and date.
i need this solution in .net.
iam working under Web application.

send to
With Regards,
Title: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed   
Name: Iquad
Date: 2008-08-16 2:43:51 AM
this code worked using gmail account from my local machine.
but when uploaded in Godaddy ,i got this eeor msg

Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

pls help me.
Title: Thank you   
Name: Sandeep
Date: 2008-07-30 9:47:59 AM
Thank you for the code.I spend my three day and finally i got solution from site.
keep it up.[:D]
Title: Getting error when setting smtp.Port   
Name: chau
Date: 2008-07-25 1:05:56 PM
I got this error when I set
smtp.Port = 587
Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
Does anyone know how to solve this?
Title: not getting mail at yahoo,gmail etc...   
Name: ankit
Date: 2008-06-18 2:33:58 AM
not getting mail at yahoo,gmail etc...
Title: The operation has timed out.   
Name: Raman
Date: 2008-06-13 2:52:11 AM
MailMessage message=new MailMessage();

message.From = new MailAddress(txtSender.Text.Trim());
message.To.Add(new MailAddress(txtReceiver.Text.Trim()));

message.Subject = txtSubject.Text.Trim(); // sets the subject property of message
message.Body = txtBody.Text.Trim(); // sets the body for the message

//message.Priority = MailPriority.High;
message.IsBodyHtml = false;
SmtpClient client = new SmtpClient("", 587);
System.Net.NetworkCredential basicAuthentication = new System.Net.NetworkCredential("","mygmailpassword");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
//Put your own, or your ISPs, mail server name onthis next line
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = basicAuthentication;

return true;

but i m getting time out problem.. its urgent... please help..
my mail id is
Title: attachment   
Name: fathur
Date: 2008-05-19 12:34:46 PM
Dear all,
I am using gmail with attachment, here the below code:

SmtpClient sc = new System.Net.Mail.SmtpClient();
sc.UseDefaultCredentials = false;
sc.Credentials = new System.Net.NetworkCredential("", "myfathur");
sc.Port = 587;
sc.Host = "";
sc.EnableSsl = true;

MailMessage mm = new MailMessage();
mm.From = new MailAddress(emailTujuan, ddlUpload.SelectedValue, System.Text.Encoding.UTF8);
mm.To.Add(new MailAddress(emailTujuan, ddlUpload.SelectedValue));
mm.Subject = "testing Ui...";
mm.Body = "Ini adalah isi body";

Attachment dataAttached = new Attachment(FileYangDiKirim);

TextBox1.Text = "Send Sukses";
catch (Exception ex)
TextBox1.Text = ex.Message;

but i found error on this. here the error message:

The SMTP server requires a secure connection or the client was not authenticated. The server response was:
5.7.0 Must issue a STARTTLS command first. q20sm13434521pog.7

any body can help me....

fathur rosi
Title: Mail format on gmail or yahoo   
Name: gunwant
Date: 2008-04-18 9:52:05 AM
Hi ,

I am using gmail smtp server to send notifications from my web application to users.

I am able to send notificatiopns to various email addresses , but those are not formatted .

All body message is comming in one line.

Please can you help me formatting the mail.

Title: Question   
Name: ber
Date: 2008-04-18 6:04:09 AM
Hi, I have tried entering an invalid password and username but I still receive the email. Is this suppose to be so ? If not, what could have happened? Thanks for your help.
Title: Worked very well   
Name: Inet26
Date: 2008-04-05 6:42:30 AM
Title: Project   
Name: Gopi
Date: 2008-04-02 10:31:11 AM
Hello sir i m doing my final year project i want code for remote mail using
Title: SMTP server error   
Name: Tushar Mehere
Date: 2008-04-01 1:30:45 AM
I got the error below:
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first g25sm6623743wag.37"

My issue got resolved with the code below:

public void MailSend()
//Add the Creddentials
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("", "yourgmailpassword);
client.Port = 587;
client.Host = "";
client.EnableSsl = true; //this is required

//Builed The MSG
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new MailAddress("", "senders name", System.Text.Encoding.UTF8);
msg.Subject = "Thanx From XYZ";
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = "Email sent thru app";
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = false;
msg.Priority = MailPriority.High;

lblErrorMessage.Text = "Message sent successfully";
catch(Exception ex)
lblErrorMessage.Text = "Message not sent";


Tushar Mehere
Title: Exception   
Name: Shaikh
Date: 2008-02-25 12:40:05 AM
Mailbox unavailable. The server response was: 5.7.1 Unable to relay for
Title: SMTP Mail Message   
Name: Lokesh
Date: 2008-02-13 8:21:18 AM
Hi I need to identified that mail sending by Smtp has been deliverd successfully to the reciever or not as the method of SMTP.Send() returns void. Having so we can not identified wethere mail has been deliverd or not.
Title: Nice Greate JOB   
Name: Anand
Date: 2008-02-07 11:36:31 PM
Title: Problem by Host   
Name: Manu Ram Pandit
Date: 2008-01-31 6:47:55 AM
"An existing connection was forcibly closed by the remote host"

Please help me to find out how to find out solution for this problem
Title: SMTP mail   
Name: inzaghi
Date: 2008-01-17 10:38:07 PM
sorry , but I tried a lot with 2 server : google mail and yahoo mail , setting host and port correctly but the program have error while trying to connect to the server for sending email . Do you really make sure that this code is already enough for running .
Title: SMTP mail Sending throuh Yahoo or GMAIL in VB6   
Name: Raza
Date: 2007-12-11 3:33:12 AM
Title: very good   
Name: mike
Date: 2007-12-08 10:05:54 PM
not bad
Title: How to send e-mail automatic via ASP.Net v2.0   
Name: Santanu Maity
Date: 2007-11-29 4:21:49 AM
How to send e-mail automatically every day in a particular time without clicking any button via ASP.Net v2.0.
And also make a schedule for fireing the mail event.
Title: too good   
Name: Sachin
Date: 2007-11-27 12:25:14 AM
Thanks for explaining the complicated concept in simple understandable words
Title: Very Good!   
Name: Patrick
Date: 2007-11-22 9:11:54 AM
Thanks for sharing, works perfectly! (had to use Rohan tip)
Title: Thanks   
Name: Mark
Date: 2007-11-16 5:28:58 PM
Thanks, that's great!
Title: Thanks   
Name: Patricia Marchand
Date: 2007-11-06 10:03:10 AM
I have spent days trying to find out how to email from 2005! thanks to you I have now done it!
(so wish packages would come with some type of documentation).
Title: Thanks for this code   
Name: sunil
Date: 2007-10-11 1:40:01 PM
Using this code i geet error:
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first b5sm4245639rva"
Please help
Title: Thanks for this code   
Name: sunil
Date: 2007-10-11 1:35:08 PM
This code gives error time out, please can u help regarding this if yes then please mail on this id thanks

with regards
Title: Tip   
Name: Rohan
Date: 2007-09-19 12:40:24 PM
One important point to note is that, if DefaultCredentials are not used then "UseDefaultCredentials" property should be set to false before setting the Credentials property. If we set UseDefaultCredentials property after setting the Credentials property then it will throw error saying: "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required ".
Actually if we dont set the UseDefaultCredentials when we use Credentials property then also it works fine.

Hope this helps... Thanks
Title: Thankyou Sir...   
Name: Umesh
Date: 2007-08-23 4:12:14 AM
It is working very fine and quick. Further do u have any sample prog. for receiving messages. If yes plz. send me link to
Title: Thank you so much   
Name: Amrit Ray
Date: 2007-07-02 9:13:54 AM
Thank you so much. I had to launch website and could find the solution for sending email to registerd users. But your solution just worked like magic. Thank you.
Title: Thank you   
Name: sandesh
Date: 2007-06-25 5:30:41 AM
Thank you very much it helped me, i was searching solution from last 4 days.

Actually my mails are getting junked when i was sending those through localhost but this code is worked for me.

But when i was running this code on local machine it was giving me errors, let it be but worked on internet

Thank you
Title: SMTP Authentication   
Name: Santosh H Raut
Date: 2007-06-24 10:16:10 AM
The above code is fantastic and it worked for me. Thanks and lots.
Title: CDO.Message   
Name: seo software reviews
Date: 2007-06-20 6:29:40 AM
Yet another .net component giving that strange CDO.Message error when there is no error at all. I recommend using rather.
Title: Mail Authentication   
Name: Srinivasa Rao
Date: 2007-06-18 7:11:03 AM
Very good article to authenticate ur domain server outgoing
Title: It's Good   
Name: Sreenivasa Rao
Date: 2007-06-18 7:09:33 AM
Very good ,this is usefull when ur domains restricting to send out from ur servers Thanks
Title: webdude   
Name: dude
Date: 2007-06-15 2:44:53 PM
THANK YOU!!!! I've been hunting around for a couple weeks now and this is the first one that laid it out so well. It worked perfectly.

And the article is from 2006 lol!
Title: Mail issue   
Name: Sree
Date: 2007-05-11 1:58:14 AM
I am not able to send the mail, when i getting the from & To mail id 's from the database. I am using sql server 2000.
Title: vlad   
Name: Multiple body parts
Date: 2007-05-03 2:30:25 AM
Hi Mail gurus. Did anyone figure out how to send multiple body parts: like text and html and then let system to choose a right one?
Title: Permission request failed!   
Name: Ali
Date: 2007-04-22 6:37:20 AM
Vivek G, thanks for the code. I have tried your code in a small application and this was what i got:
Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Any thoughts anyone?
Title: Great!!! it works   
Name: Vivek G
Date: 2007-03-22 2:39:53 PM
Try this, it will work
//Port was 587
MailMessage msgMail = new MailMessage("", "");
msgMail.Subject = "Test";
msgMail.Body = "Test";
SmtpClient s = new SmtpClient();
s.Host = "";
NetworkCredential basicAuthenticationInfo = new NetworkCredential("", "mailpassword");
s.UseDefaultCredentials = false;
s.Credentials = basicAuthenticationInfo;
s.EnableSsl = true;
Title: send mail working   
Name: jero
Date: 2007-03-20 10:38:26 PM
Thank you every much for sharing your email sending code. Now I have run it successfully.
Title: Thanks   
Name: Dardino
Date: 2007-03-15 7:31:56 AM
Thanks, Thanks, Thanks, Very Thanks!!
Title: No Auth   
Name: Brad
Date: 2007-02-26 6:31:05 AM
Sure, code for no authentication is here:
Managed Complex Hosting
#1 in Service and Support
Title: is there any way to send mail without authentication..??   
Name: virat
Date: 2007-02-23 12:31:31 AM
this article is very helpful...
but i want to know is there any way to send mail without giving authentication to smtp server...???
Title: Excellent   
Name: MajorHB
Date: 2007-02-14 5:39:37 AM
Excellent example, helped me... keep continuing to submit sound solutions! Thank You.
Title: sending mail with authentication   
Name: Barbara
Date: 2007-01-28 10:12:22 AM
HI! Can someone help me with this error. I am trying to send an e-mail with ASP.NET

With the following code I get e time-out error operation.

MailMessage mail = new MailMessage("", ""); mail.Subject = TextBox1.Text;
mail.Body = TextBox4.Text;
SmtpClient smtp = new SmtpClient("", 465);
smtp.Credentials = new NetworkCredential("", "xxxxx");
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

If I use and port 587 I get error:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required h20sm9797379wxd

In gmail I enabled POP for all mail.

Please, help me. Thanks.
Title: send SMTP authenticated e-mail using ASP.NET 2.0   
Name: Karen
Date: 2007-01-18 11:49:10 PM
I have tried miles of code and nothing works. This should not be this difficult! I'm using GoDaddy for my site so I've found lots of references to problems related to them. None of those fixes work. The code all looks pretty much the same but I cannot get any of it to send mail.

I have a very simple form with a Done button. When the user clicks the button, the form info goes to my Access database. What I want is to get an automatic e-mail whenever someone fills out the form. I'm using VWD Express, ASP.NET 2.0, GoDaddy, Windows XP... what else should I tell you except I have spent way too many hours Fussing with this. Can anyone, someone, please help me?
Title: Please Help   
Name: Sean
Date: 2006-12-15 12:53:10 AM
I have been tryin to use similar code but using yahoo smtpp server. Will that work? if yes can you provide me with the code please
Title: Another example on how to send emails using 2.0   
Name: Mr DotNet
Date: 2006-12-05 9:15:28 PM
Simple SMTP Authenticated example on how to send emails using 2.0 with C#. It uses
works for 2.0 version.
Title: email successfully sent?   
Name: Brad Kingsley
Date: 2006-11-03 7:06:50 PM
You would need to check the SMTP service logs. The code just hands off to the SMTP service and doesn't know for sure if the email is delivered or not.

Title: doubt   
Name: ali
Date: 2006-11-03 5:56:31 AM
Dear sir, how can we confirm that the email is successfully sent? any return values from the smtp server?
Title: Yahoo SMTP   
Name: Brad
Date: 2006-10-25 11:01:50 AM

It sounds like you are trying to use Yahoo's mail server for the mailClient.Host setting. You cannot do this - they will not allow it because of their spam controls. You should use either your local SMTP service running on your machine, or the SMTP server for your ISP.

Title: Cannot send email to Yahoo!   
Name: Ally
Date: 2006-10-25 8:41:46 AM

Example is great...except that I cannot send email to Yahoo! I've checked Sender/From, usrname, password, Server/IP/port and ven firewall, but I kept getting this message :

System.Net.Mail.SmtpException: Erreur de syntaxe, commande non reconnue. La réponse du serveur était : closing transmission channel. You must be pop-authenticated before you can use this smtp server, and you must use your yahoo mail address for the Sender/From field.
à System.Net.Mail.SendMailAsyncResult.End(IAsyncResult result)
à System.Net.Mail.SmtpTransport.EndSendMail(IAsyncResult result)
à System.Net.Mail.SmtpClient.SendMailCallback(IAsyncResult result)

Can u shed any light
Title: Sending email   
Name: Steve Schofield
Date: 2006-10-12 8:27:25 AM
Thanks DJ for posting the code to connect to gmail.
Title: Re: A Method for Google   
Name: wy
Date: 2006-10-12 12:08:16 AM
Hey DJ. Thanks a lot for the google code. i was pulling my hair out trying to figure out how to get it working with google. I was just wondering if you knew why it didn't work with the settings that gmail tells us to use with our mail clients: smtp server:
port: 465

these are the settings i use in outlook and they work fine. why not in .NET?
Title: A method that works for google   
Name: DJ Entwine
Date: 2006-10-10 4:22:44 PM
Dim Email As New System.Net.Mail.MailMessage("", "")

With Email
.Subject = "Your subject text"
.Body = "Your body text"
End With

Dim basicAuthenticationInfo As New System.Net.NetworkCredential("", "YourGmailAccountPassword")

Dim mailClient As New System.Net.Mail.SmtpClient()
With mailClient
.Host = ""
.Port = 587
.UseDefaultCredentials = False
.Credentials = basicAuthenticationInfo
.EnableSsl = True
End With
Title: I   
Name: Query
Date: 2006-09-25 2:04:55 AM
I get this error

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first w66sm2217730pyw

Can anybody help me out what is wrong with following code

protected void btnSendEmail_Click(object sender, EventArgs e)
System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("","", "This is the mail subject", "Just wanted to say Hello");

MyMailMessage.IsBodyHtml = false;

System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential("mymail", "mypass");

System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("",587);

mailClient.UseDefaultCredentials = false;

mailClient.Credentials = mailAuthentication;
//mailClient.Credentials = CredentialCache.DefaultNetworkCredentials;

//mailClient.Credentials = mailAuthentication;

Title: no ssl in mailsetting smtp?   
Name: ryanDev
Date: 2006-09-06 5:24:49 PM
I'm having the same problem. Sure I can make a SendMail class which uses the EnableSSl method, but how do you set up the mailsetting->smtp in web.config to use the SSL?

How can I use the MailDefinition functions in controls. Such as sending registration confirmation emails with the CreateUserWizard?
Title: Not working   
Name: Mr X
Date: 2006-09-05 3:31:04 AM
They said it all!

Same problem with gmail
Title: problem: smtpclient ssl   
Name: JJ
Date: 2006-08-31 1:55:04 AM
I've the same problem with gmail.
I store mail-content into a database and then i want to send it with smtpclient()


Dim smtp As New SmtpClient()
smtp.Host = ds.tables(0).rows(0)("smtp_server")
smtp.Port = ds.tables(0).rows(0)("port")
smtp.EnableSsl = true
smtp.UseDefaultCredentials = False
smtp.DeliveryMethod = SmtpDeliveryMethod.Network
smtp.Credentials = New NetworkCredential(ds.tables(0).rows(0)("login"),ds.tables(0).rows(0)("passwd"))
Title: Doesnt work   
Name: Scott Forsyth
Date: 2006-08-21 9:31:30 AM
Hi Jeff,

That suggests that your SMTP server requires a secure connection. You can force that using:
mailClient.EnableSsl = True

Title: Doesnt work   
Name: Jeff
Date: 2006-08-21 9:20:25 AM
This code doesnt work with any of the email providers that i have tried that need authentication. I especially want this authentication to work with gmail. The error message i get is "System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first h15sm4738093wxd"
Title: Does not work with my ISP   
Name: Scott
Date: 2006-08-20 4:09:11 PM
These settings are not authenticating for me. The error says: Service not available, closing transmission channel. The server response was: Sorry, you must log in before using this server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: Service not available, closing transmission channel. The server response was: Sorry, you must log in before using this server.

Source Error:

Line 22: mailClient.UseDefaultCredentials = False
Line 23: mailClient.Credentials = basicAuthenticationInfo
Line 24: mailClient.Send(Email)
Line 25:
Line 26: End Sub
Title: not working   
Name: zjs
Date: 2006-07-09 4:58:34 AM
Even when i use NetworkCredential("username", "password") and try this on not only one smtp server, connection throw same error: that domain isn´t in my list of allowed rcpthosts (#5.7.1). It seems that SmtpClient does not use Credentails. Why?
Title: MR.   
Name: Scott
Date: 2006-06-29 9:09:17 PM
I have tried the code you have at the top, but I get This transmission has been terminated, you need to log in to use this service.
Title: Paris   
Name: Sample config file
Date: 2006-06-02 4:25:57 PM
It seems I cannot post samples with tags here. In the following example, replace { and } by the equivalent tag brackets. Then this will be a simple sample of a web.config initializing your authenticated emails
{!-- your other settings here --}
{network host="" password="myPassword" userName="myUserName" port="25" defaultCredentials="false" /}

Title: Alternate method   
Name: Paris
Date: 2006-06-02 4:22:18 PM
This article is great!!
However, one can achieve the same results by hardcoding the authentication details in the web.config file, in the section.
Then you can omit all the coding of the host & credentials. They are all loaded from the config from the default constructor. Just do:
Dim mailClient As New System.Net.Mail.SmtpClient()
and the mail will be sent

Product Spotlight
Product Spotlight 

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

©Copyright 1998-2024  |  Page Processed at 2024-06-15 9:54:31 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search