TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abraham Olatubosun
NA
471
113.7k
Error When Sending Mail With Asp.net C#
Jan 24 2017 10:08 AM
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
Reply
Answers (
4
)
How to make default value for combobox with selectedvalue=0
C# Relative Folder Directory Structure via Savepath filename