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

 

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( _
   "Brad.Kingsley@orcsweb.com", "Brad@KingsleyTeam.com")
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 = "Mail.RemoteMailServer.com"
mailClient.UseDefaultCredentials = False
mailClient.Credentials = basicAuthenticationInfo
mailClient.Send(Email)

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: 1/7/2013 4:03:52 AM
Comment:
jlskflsklfj
Title: 567657   
Name: 56756
Date: 11/21/2012 2:12:44 AM
Comment:
567657
Title: aaa   
Name: dsfd
Date: 8/24/2012 3:44:36 AM
Comment:
dff
Title: sdcas   
Name: dcsdc
Date: 7/19/2012 2:54:11 PM
Comment:
dfvdfv
Title: auto email in asp.net   
Name: wotwow
Date: 7/11/2012 11:19:20 PM
Comment:
Please teach me how to use smtp in asp.net.

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


send me an email at wotwow123@gmail.com
Title: mnlk   
Name: gjkhjhjkhjkhj
Date: 6/15/2012 1:48:30 AM
Comment:
svknnkljn
Title: fdsf   
Name: fds
Date: 6/13/2012 2:51:59 AM
Comment:
fd
Title: mailClient   
Name: mailClient
Date: 6/6/2012 10:04:46 AM
Comment:
mailClient
Title: jkjhkj   
Name: kjhkh
Date: 5/29/2012 4:27:19 AM
Comment:
lkjhk
Title: ,m ,m   
Name: ,m,.m
Date: 5/22/2012 4:30:36 AM
Comment:
mn,mn
Title: Thanks! Works good   
Name: Haim
Date: 3/15/2012 9:18:07 AM
Comment:
this is first place i found how to provide credentials without use web.config
Title: C# SMTP MAIL   
Name: saviolan
Date: 2/2/2012 12:34:23 PM
Comment:
try this simple asp.net smtp mail with authentication

http://asp.net-informations.com/communications/asp-email.htm

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

Thanks&Regards
Title: Thank you!!   
Name: Dustin
Date: 2/18/2011 4:46:10 PM
Comment:
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: 2/17/2011 1:46:06 AM
Comment:
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 = "smtp.mail.yahoo.com";
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";



smtpClient.Send(message);
lblStatus.Text = "Email successfully sent.";


lblStatus.Text = "Send Email Failed." + ex.Message;
Title: Receiving Mail   
Name: Bibhuti Bhusan Kar
Date: 11/22/2010 8:06:04 AM
Comment:
How to receive mail from my gmail to werb server mailbox
Title: Imp Code block   
Name: Coder
Date: 10/20/2010 1:31:59 AM
Comment:
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: 9/17/2010 5:05:40 AM
Comment:
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
ronniooo@hotmail.com

thanking you in advance

Ron
Title: how to send   
Name: Rajesh
Date: 9/5/2010 9:01:46 AM
Comment:
hai, anyone explines me about how to send this code via e-mail explain me and send the mail at rrrajeshcool@gmail.com
Title: Email code in asp.net and c #   
Name: Himanshu
Date: 8/3/2010 11:27:53 PM
Comment:
Hi,
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: 7/24/2010 6:41:43 AM
Comment:
hi,
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: 7/24/2010 5:29:33 AM
Comment:
hi,
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: 7/21/2010 4:14:56 PM
Comment:
@Jhon -- see http://systemnetmail.com
Title: SMTP configutration?   
Name: Jhon
Date: 7/21/2010 4:02:38 PM
Comment:
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.
Thanks...
Title: Solved!   
Name: Elvin Meza
Date: 7/3/2010 4:42:26 AM
Comment:
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: 6/13/2010 4:11:53 PM
Comment:
In "username" type first part of your email address i.e if your email address is 'example@gmail.com' then username will be 'example'
Title: article feedback   
Name: amit kumar
Date: 6/12/2010 6:13:53 AM
Comment:
Thank you
Title: CC a copy   
Name: Roy, Singapore
Date: 5/13/2010 1:22:07 AM
Comment:
How to make a cc copy from the sample scripts?
Title: Authentication problem   
Name: Soren Berghall, Sweden
Date: 5/6/2010 11:16:22 AM
Comment:
Thanks, this solved my problem! Just to transform the code into C#!
Title: Thanks   
Name: MCasanova
Date: 4/14/2010 5:59:56 AM
Comment:
Thanks, Dominik GOLDSCHMIDT, moving the usedefault credentials did the trick for me
Title: error   
Name: stalin
Date: 4/10/2010 7:29:08 AM
Comment:
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: 4/9/2010 8:36:00 AM
Comment:
This below code is using System.web.mail, and now i have to use system.net.mail . plesae tell me what code will be used ??


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

CustomerMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", strMailServer);

CustomerMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", cdoPort);

CustomerMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", cdoSendUsing);

CustomerMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", cdoAuthentication);
CustomerMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName);

CustomerMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
Title: Mr   
Name: Rob Porto
Date: 3/28/2010 2:52:28 PM
Comment:
Thanks. Finally a good answer!
Title: kanwal   
Name: kanwalsodha
Date: 3/16/2010 3:44:37 AM
Comment:
Hello Dear Plz tell me smtp send fail message
Title: nike shoes   
Name: nike shoes
Date: 3/14/2010 10:39:58 PM
Comment:
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   
Name: Dominik GOLDSCHMIDT
Date: 2/24/2010 4:10:14 AM
Comment:
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: 2/23/2010 1:25:47 AM
Comment:
Can you help me for read emails from smtp email account.
Title: How to pass windows credentials   
Name: Kiran Ayyagari
Date: 1/28/2010 3:50:32 PM
Comment:
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.To.Add("aaa@aa.com");
message.Subject = "This is the Subject line";
message.From =new System.Net.Mail.MailAddress("aaa@aa.com");
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;
smtp.Send(message);
Title: how to solve operational time out problem   
Name: Amir
Date: 1/28/2010 4:19:16 AM
Comment:
i got a problem when i send a mail through asp dot net "operational time out" plz help me.is 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: 1/14/2010 6:51:22 AM
Comment:
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: 1/5/2010 7:46:47 PM
Comment:
Hi again,

I just saw a video from Asp.net site and they build an application with login control and the link when users forgot they password.They configured the smtp in application of asp.net 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: naim.latifi@gmail.com

Thanks in advanced !
Naim
Title: Connect with server or send the forgot password in email   
Name: naim
Date: 1/5/2010 7:35:57 PM
Comment:
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!

Regards,
Title: Sending Email Without any Mail Client And CDOS   
Name: Sadashiv Palde
Date: 12/16/2009 2:39:05 AM
Comment:
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: 11/19/2009 2:20:56 AM
Comment:
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 74.125.47.109:25"
I am using emailsend facilities on particular website.
Thanks.
Title: check this out   
Name: Anand
Date: 11/18/2009 2:44:30 PM
Comment:
check this out http://dotnetbeginner.spaces.live.com/blog/cns!C878CA0BAA85841F!157.entry
Title: Automatic Sending E-mail   
Name: Jaime Corte Real
Date: 10/30/2009 7:43:30 AM
Comment:
Sridhar, use the scheduler task.
Title: sending mail   
Name: sridhar
Date: 10/4/2009 9:11:06 AM
Comment:
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: 9/7/2009 12:44:48 AM
Comment:
the above code is good. I need to send mails automatically everyday.How can i add windows services.
Title: sending Mail   
Name: Quest
Date: 8/28/2009 5:38:23 AM
Comment:
good one which is useful to me

thanks
Quest
Title: send msg with defualt credential in asp.net   
Name: sanjay
Date: 8/10/2009 8:50:13 AM
Comment:
please help me how send send email msg with defualt credential in asp.net
Title: Jojo   
Name: jojo
Date: 7/29/2009 3:01:49 AM
Comment:
Thanks for this
It worked for me
Title: Web Design Company   
Name: Software Company
Date: 7/22/2009 12:54:05 AM
Comment:
Nice article.
Title: mr   
Name: finder
Date: 7/12/2009 3:48:23 PM
Comment:
thanku
Title: Sending mail Using Guest Account   
Name: Anubhava Dimri
Date: 7/11/2009 12:45:00 AM
Comment:
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: 7/9/2009 10:21:35 AM
Comment:
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("almiro.alves@using.com.br");
msg.To.Add(new MailAddress("almiro.alves@using.com.br"));
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 = "smtpout.secureserver.net";
smtp.Port = 80;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("almiro.alves", "******", "using.com.br");
smtp.Send(msg);


Anyboy help me please for this problem?

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

pls Reply.
Title: Sending mail For Hotmail   
Name: Anubhava Dimri
Date: 5/30/2009 2:46:16 AM
Comment:
Hello All,
I have generating one issue regarding to sending mail by hotmail.
Title: something difference   
Name: gogoahead
Date: 5/19/2009 12:38:51 PM
Comment:
my code works fine,and like this:
MailMessage mm = new MailMessage();
mm.From = new MailAddress("from@gmail.com");
mm.To.Add(new MailAddress("to@mail.com"));
mm.Subject = "hi";
mm.Body = "hi";
mm.IsBodyHtml = false;
SmtpClient sc = new SmtpClient();
sc.Host = "smtp.gmail.com";
sc.Port = 587;
sc.Credentials = new NetworkCredential("from@gmail.com", "password");
sc.EnableSsl = true;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Send(mm);
the main code works fine ,but when i add the line "sc.UseDefaultCredentials =false;" like the article does.it'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: 4/6/2009 2:40:48 AM
Comment:
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   
Name: khalidmehmoodawan@gmail.com
Date: 3/31/2009 5:39:23 AM
Comment:
thanks for the code.

It worked for me.
Title: Operation Time out error.   
Name: Manjusha
Date: 2/27/2009 6:17:26 AM
Comment:
My mail ID is manjusha.dhabale@gmail.com
Title: The operation has timed out.   
Name: Manjusha
Date: 2/27/2009 6:15:14 AM
Comment:
try
{
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++)
{


items.Add(EmpInfoItems[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: 2/23/2009 5:23:22 PM
Comment:
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 (myemail@gmail.com). 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: 2/20/2009 5:24:11 AM
Comment:
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: 2/17/2009 5:21:01 AM
Comment:
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: 2/16/2009 5:55:08 PM
Comment:
Perfect mate. Bailed me out of trouble. Now it makes sense
Title: Almost there   
Name: Martin
Date: 2/10/2009 12:25:05 PM
Comment:
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: 2/4/2009 8:31:03 PM
Comment:
Thank you, exactly what I needed.
Title: Good Article   
Name: Thomas
Date: 12/16/2008 2:19:59 AM
Comment:
This is good article.For gmail authentication chech
http://techdotnets.blogspot.com/
Title: great thanks   
Name: andrew
Date: 11/22/2008 4:49:06 PM
Comment:
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: 11/11/2008 12:42:06 AM
Comment:
plz help me....
urgent plz give me a code for send a mail using SMTP
Title: SMTP porblem   
Name: chetan
Date: 10/15/2008 2:35:24 AM
Comment:
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: 10/6/2008 7:26:26 AM
Comment:
my email is sending failed.becuse of smtp
Title: Useless   
Name: Shefali
Date: 9/19/2008 7:42:49 AM
Comment:
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: 9/18/2008 6:27:51 AM
Comment:
Please send me the Code to receive the Mail on my ASP.net page and also code to receive Delivery Reports. Please help me .........
Title: gmail smtp   
Name: Rahul Anand
Date: 9/15/2008 11:46:02 PM
Comment:
Please send me the Code to receive the Mail on my ASP.net page and also code to receive Delivery Reports. Please help me
Title: Email only comes from Credential user   
Name: Russ
Date: 9/8/2008 12:44:21 PM
Comment:
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!

Russ
Title: where is delivery reports for sending mail   
Name: sasikumar
Date: 9/5/2008 9:57:07 AM
Comment:
i use smtpsend mail option .. i send perfact but not recived delivery reports ..how is possible that one ?
Title: Thanks a Lot   
Name: Samuel Rajan
Date: 9/4/2008 8:54:01 AM
Comment:
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: 9/4/2008 4:14:13 AM
Comment:
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 ashwinkumar.samba@gmail.com
With Regards,
Ashwin
Title: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed   
Name: Iquad
Date: 8/16/2008 2:43:51 AM
Comment:
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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

pls help me.
Title: Thank you   
Name: Sandeep
Date: 7/30/2008 9:47:59 AM
Comment:
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: 7/25/2008 1:05:56 PM
Comment:
I got this error when I set
smtp.Port = 587
Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
Does anyone know how to solve this?
Thanks,
Chau
Title: not getting mail at yahoo,gmail etc...   
Name: ankit
Date: 6/18/2008 2:33:58 AM
Comment:
not getting mail at yahoo,gmail etc...
Title: The operation has timed out.   
Name: Raman
Date: 6/13/2008 2:52:11 AM
Comment:
try
{
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("smtp.googlemail.com", 587);
System.Net.NetworkCredential basicAuthentication = new System.Net.NetworkCredential("pundirraman@gmail.com","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;

client.Send(message);
return true;
}

but i m getting time out problem.. its urgent... please help..
my mail id is pundirraman@gmail.com
Title: attachment   
Name: fathur
Date: 5/19/2008 12:34:46 PM
Comment:
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("fathur027@gmail.com", "myfathur");
sc.Port = 587;
sc.Host = "smtp.gmail.com";
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);
mm.Attachments.Add(dataAttached);

try
{
sc.Send(mm);
mm.Dispose();
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....

thanks
fathur rosi
fa-thur@hotmail.com
Title: Mail format on gmail or yahoo   
Name: gunwant
Date: 4/18/2008 9:52:05 AM
Comment:
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.

Regards
Gunwant
Title: Question   
Name: ber
Date: 4/18/2008 6:04:09 AM
Comment:
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: 4/5/2008 6:42:30 AM
Comment:
Thanks....
Title: Project   
Name: Gopi
Date: 4/2/2008 10:31:11 AM
Comment:
Hello sir i m doing my final year project i want code for remote mail using asp.net
Title: SMTP server error   
Name: Tushar Mehere
Date: 4/1/2008 1:30:45 AM
Comment:
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("yourgmailusername@gmail.com", "yourgmailpassword);
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true; //this is required


//Builed The MSG
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add("someemailid@gmail.com");
msg.To.Add("anotheremailid@gmail.com");
msg.From = new MailAddress("sendersemail@gmail.com", "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;

try
{
client.Send(msg);
lblErrorMessage.Text = "Message sent successfully";
}
catch(Exception ex)
{
lblErrorMessage.Text = "Message not sent";
}


}


Thanx,
Tushar Mehere
Title: Exception   
Name: Shaikh
Date: 2/25/2008 12:40:05 AM
Comment:
Mailbox unavailable. The server response was: 5.7.1 Unable to relay for akhtar195@gmail.com
Title: SMTP Mail Message   
Name: Lokesh
Date: 2/13/2008 8:21:18 AM
Comment:
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: 2/7/2008 11:36:31 PM
Comment:
Great!!
Title: Problem by Host   
Name: Manu Ram Pandit
Date: 1/31/2008 6:47:55 AM
Comment:
"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: 1/17/2008 10:38:07 PM
Comment:
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: 12/11/2007 3:33:12 AM
Comment:
\
Title: very good   
Name: mike
Date: 12/8/2007 10:05:54 PM
Comment:
not bad
Title: How to send e-mail automatic via ASP.Net v2.0   
Name: Santanu Maity
Date: 11/29/2007 4:21:49 AM
Comment:
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: 11/27/2007 12:25:14 AM
Comment:
Thanks for explaining the complicated concept in simple understandable words
regards
Title: Very Good!   
Name: Patrick
Date: 11/22/2007 9:11:54 AM
Comment:
Thanks for sharing, works perfectly! (had to use Rohan tip)
Title: Thanks   
Name: Mark
Date: 11/16/2007 5:28:58 PM
Comment:
Thanks, that's great!
Title: Thanks   
Name: Patricia Marchand
Date: 11/6/2007 10:03:10 AM
Comment:
I have spent days trying to find out how to email from asp.net 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: 10/11/2007 1:40:01 PM
Comment:
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
thanks
Title: Thanks for this code   
Name: sunil
Date: 10/11/2007 1:35:08 PM
Comment:
This code gives error time out, please can u help regarding this if yes then please mail on this id sunil_raina77@yahoo.com thanks

with regards
sunil
Title: Tip   
Name: Rohan
Date: 9/19/2007 12:40:24 PM
Comment:
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: 8/23/2007 4:12:14 AM
Comment:
It is working very fine and quick. Further do u have any sample prog. for receiving messages. If yes plz. send me link to umeshsvb@rediffmail.com
Title: Thank you so much   
Name: Amrit Ray
Date: 7/2/2007 9:13:54 AM
Comment:
Thank you so much. I had to launch www.2findnow.com 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: 6/25/2007 5:30:41 AM
Comment:
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: 6/24/2007 10:16:10 AM
Comment:
The above code is fantastic and it worked for me. Thanks and lots.
Title: CDO.Message   
Name: seo software reviews
Date: 6/20/2007 6:29:40 AM
Comment:
Yet another .net component giving that strange CDO.Message error when there is no error at all. I recommend using FreeSmtp.net rather.
Title: Mail Authentication   
Name: Srinivasa Rao
Date: 6/18/2007 7:11:03 AM
Comment:
Very good article to authenticate ur domain server outgoing
Title: It's Good   
Name: Sreenivasa Rao
Date: 6/18/2007 7:09:33 AM
Comment:
Very good ,this is usefull when ur domains restricting to send out from ur servers Thanks
Title: webdude   
Name: dude
Date: 6/15/2007 2:44:53 PM
Comment:
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: 5/11/2007 1:58:14 AM
Comment:
Hi,
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: 5/3/2007 2:30:25 AM
Comment:
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: 4/22/2007 6:37:20 AM
Comment:
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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Any thoughts anyone?
Title: Great!!! it works   
Name: Vivek G
Date: 3/22/2007 2:39:53 PM
Comment:
Try this, it will work
//Port was 587
MailMessage msgMail = new MailMessage("yourmail@gmail.com", "tomailid@yahoo.com");
msgMail.Subject = "Test";
msgMail.Body = "Test";
SmtpClient s = new SmtpClient();
s.Host = "smtp.gmail.com";
NetworkCredential basicAuthenticationInfo = new NetworkCredential("yourmail@gmail.com", "mailpassword");
s.UseDefaultCredentials = false;
s.Credentials = basicAuthenticationInfo;
s.EnableSsl = true;
s.Send(msgMail);
Title: send mail working   
Name: jero
Date: 3/20/2007 10:38:26 PM
Comment:
Thank you every much for sharing your email sending code. Now I have run it successfully.
Title: Thanks   
Name: Dardino
Date: 3/15/2007 7:31:56 AM
Comment:
Thanks, Thanks, Thanks, Very Thanks!!
Title: No Auth   
Name: Brad
Date: 2/26/2007 6:31:05 AM
Comment:
Sure, code for no authentication is here:
http://www.orcsweb.com/articles/send_email_from_dotnetv2.aspx

http://www.orcsweb.com
Managed Complex Hosting
#1 in Service and Support
Title: is there any way to send mail without authentication..??   
Name: virat
Date: 2/23/2007 12:31:31 AM
Comment:
this article is very helpful...
but i want to know is there any way to send mail without giving authentication to smtp server...???
reply..
Title: Excellent   
Name: MajorHB
Date: 2/14/2007 5:39:37 AM
Comment:
Excellent example, helped me... keep continuing to submit sound solutions! Thank You.
Title: sending mail with authentication   
Name: Barbara
Date: 1/28/2007 10:12:22 AM
Comment:
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("barbara.prueba@gmail.com", "barbara.prueba@gmail.com"); mail.Subject = TextBox1.Text;
mail.Body = TextBox4.Text;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 465);
smtp.Credentials = new NetworkCredential("barbara.prueba@gmail.com", "xxxxx");
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(mail);

If I use smtp.googlemail.com 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: 1/18/2007 11:49:10 PM
Comment:
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: 12/15/2006 12:53:10 AM
Comment:
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 asp.net 2.0   
Name: Mr DotNet
Date: 12/5/2006 9:15:28 PM
Comment:
Simple SMTP Authenticated example on how to send emails using asp.net 2.0 with C#. It uses


http://www.dotnetspace.com/articles/general-articles/sending-emails.html
works for asp.net 2.0 version.
Title: email successfully sent?   
Name: Brad Kingsley
Date: 11/3/2006 7:06:50 PM
Comment:
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.

~bk
Title: doubt   
Name: ali
Date: 11/3/2006 5:56:31 AM
Comment:
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: 10/25/2006 11:01:50 AM
Comment:
Ally,

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.

~Brad
Title: Cannot send email to Yahoo!   
Name: Ally
Date: 10/25/2006 8:41:46 AM
Comment:
Hi!

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 : yahoo.com 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: 10/12/2006 8:27:25 AM
Comment:
Thanks DJ for posting the code to connect to gmail.
Title: Re: A Method for Google   
Name: wy
Date: 10/12/2006 12:08:16 AM
Comment:
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: smtp.google.com
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: 10/10/2006 4:22:44 PM
Comment:
Dim Email As New System.Net.Mail.MailMessage("from@gmail.com", "to@gmail.com")

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

Dim basicAuthenticationInfo As New System.Net.NetworkCredential("YourGmailGccount@gmail.com", "YourGmailAccountPassword")

Dim mailClient As New System.Net.Mail.SmtpClient()
With mailClient
.Host = "smtp.googlemail.com"
.Port = 587
.UseDefaultCredentials = False
.Credentials = basicAuthenticationInfo
.EnableSsl = True
.Send(Email)
End With
Title: I   
Name: Query
Date: 9/25/2006 2:04:55 AM
Comment:
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("mymail@gmail.com","anymail@i-link.co.in", "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("smtp.gmail.com",587);

mailClient.UseDefaultCredentials = false;

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

//mailClient.Credentials = mailAuthentication;

mailClient.Send(MyMailMessage);
}
Title: no ssl in mailsetting smtp?   
Name: ryanDev
Date: 9/6/2006 5:24:49 PM
Comment:
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: 9/5/2006 3:31:04 AM
Comment:
They said it all!

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

Source:
--------

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"))
Smtp.Send(msgMail)
Title: Doesnt work   
Name: Scott Forsyth
Date: 8/21/2006 9:31:30 AM
Comment:
Hi Jeff,

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

Scott
Title: Doesnt work   
Name: Jeff
Date: 8/21/2006 9:20:25 AM
Comment:
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: 8/20/2006 4:09:11 PM
Comment:
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: 7/9/2006 4:58:34 AM
Comment:
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: 6/29/2006 9:09:17 PM
Comment:
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: 6/2/2006 4:25:57 PM
Comment:
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
{configuration}
{system.web}
{!-- your other settings here --}
{/system.web}
{system.net}
{mailSettings}{smtp}
{network host="smtp.muhost.com" password="myPassword" userName="myUserName" port="25" defaultCredentials="false" /}
{/smtp}{/mailSettings}
{/system.net}
{/configuration}

}}}
Title: Alternate method   
Name: Paris
Date: 6/2/2006 4:22:18 PM
Comment:
This article is great!!
However, one can achieve the same results by hardcoding the authentication details in the web.config file, in the system.net 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()
mailClient.Send(Email)
and the mail will be sent

Product Spotlight
Product Spotlight 





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


©Copyright 1998-2014 ASPAlliance.com  |  Page Processed at 12/20/2014 2:59:23 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search