Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
4
Reply
Error When Sending Mail With Asp.net C#
Abraham Olatubosun
Jan 24 2017 10:08 AM
377
Reply
Hello all,
I want to send a mail after my user fill a form but i keep getting the following error "
The smtp server requires a secure connection or the client was not authenticated 5.5.1. Authentication required
". bellow is my code :
int
cnt;
try
{
mEmail = Session[
"mEmail"
].ToString();
// string password = "abraham@2013";
MailMessage Msg =
new
MailMessage();
Msg.From =
new
MailAddress(mEmail.Trim());
Msg.To.Add(
"
[email protected]
"
);
// create a frame for HR department
Msg.Bcc.Add(
"
[email protected]
"
);
//blind copy me
StreamReader reader =
new
StreamReader(Server.MapPath(
"~/SendMail.html"
));
string
readFile = reader.ReadToEnd();
string
StrContent =
""
;
StrContent = readFile;
//Here replace the name with [MyName]
StrContent = StrContent.Replace(
"[MyName]"
, lblname.Text);
string
mSubject =
"APPLICATION FOR ANNUAL LEAVE"
;
StrContent = StrContent.Replace(
"[subject]"
, mSubject);
StrContent = StrContent.Replace(
"[date1]"
, txtFromDate.Text.Trim());
StrContent = StrContent.Replace(
"[date2]"
, txtToDate.Text.Trim());
StrContent = StrContent.Replace(
"[ddays]"
,txtNODays.Text.Trim())+
" days"
;
Msg.Subject = mSubject +
" FROM "
+ lblname.Text;
Msg.Body = StrContent.ToString();
Msg.IsBodyHtml =
true
;
SmtpClient smtp =
new
SmtpClient();
smtp.Host =
"smtp.gmail.com"
;
//"mail.dnextageweb.com"; //
smtp.Port = 587;
smtp.EnableSsl =
true
;
smtp.Timeout = 40000;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials =
false
;
smtp.Credentials =
new
NetworkCredential(
"
[email protected]
"
,
"Delladv!973@"
);
smtp.Send(Msg);
webMessage.Show(
"Mail sent successful....."
);
return
cnt = 1;
}
catch
(Exception ex)
{
webMessage.Show(
"Error : "
+ ex.Message.ToString());
return
cnt = -1;
}
please i have tried all i know, i need your help, how to get smtp.gmail.com to work.
Thank you all
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
How to make default value for combobox with selectedvalue=0
C# Relative Folder Directory Structure via Savepath filename