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
Muhammad Nadeem
NA
548
66.9k
mail not send in asp.net
Sep 5 2016 6:03 AM
my mail not sent I also include gmailsend.dll but failure sending mail. message will show in catch block.
Reply
Answers (
6
)
0
Ajay Malik
0
4.7k
1.6m
Sep 6 2016 7:47 AM
try this code
protected
void
btn_send_Click(
object
sender, EventArgs e)
{
System.Net.Mail.MailMessage mail =
new
System.Net.Mail.MailMessage();
mail.To.Add(
"to gmail address"
);
mail.From =
new
MailAddress(
"from gmail address"
,
"Email head"
, System.Text.Encoding.UTF8);
mail.Subject =
"This mail is send from asp.net application"
;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body =
"This is Email Body Text"
;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml =
true
;
mail.Priority = MailPriority.High;
SmtpClient client =
new
SmtpClient();
client.Credentials =
new
System.Net.NetworkCredential(
"from gmail address"
,
"your gmail account password"
);
client.Port = 587;
client.Host =
"smtp.gmail.com"
;
client.EnableSsl =
true
;
try
{
client.Send(mail);
Page.RegisterStartupScript(
"UserMsg"
,
"<script>alert('Successfully Send...');if(alert){ window.location='SendMail.aspx';}</script>"
);
}
catch
(Exception ex)
{
Exception ex2 = ex;
string
errorMessage =
string
.Empty;
while
(ex2 !=
null
)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
Page.RegisterStartupScript(
"UserMsg"
,
"<script>alert('Sending Failed...');if(alert){ window.location='SendMail.aspx';}</script>"
);
}
Accepted Answer
0
Rajeesh Menoth
67
27k
2.7m
Sep 6 2016 6:37 AM
Hi,
Instead of 465 Use 587 port id.
SmtpClient client =
new
SmtpClient(
"smtp.gmail.com"
, 587);
//Gmail smtp
Reference :
http://www.c-sharpcorner.com/blogs/smtp-server-requires-a-secure-connection1
0
Muhammad Nadeem
0
548
66.9k
Sep 6 2016 6:34 AM
I try this code but still I cannot send mail.
protected void Page_Load(object sender, EventArgs e)
{
string to = "tazeemjaan73@gmail.com"; //To address
string from = "tazeemjaan73@gmail.com"; //From address
MailMessage message = new MailMessage(from, to);
string mailbody = "In this article you will learn how to send a email using Asp.Net & C#";
message.Subject = "Sending Email Using Asp.Net & C#";
message.Body = mailbody;
message.BodyEncoding = Encoding.UTF8;
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com", 465); //Gmail smtp
System.Net.NetworkCredential basicCredential1 = new
System.Net.NetworkCredential("tazeemjaan73@gmail.com", "12345");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = basicCredential1;
try
{
client.Send(message);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
0
Rajeesh Menoth
67
27k
2.7m
Sep 5 2016 7:41 AM
Hi,
First of all check the given gmail smtp port id is "587" then it will work. You need to check more about sending mail using C#.
Please check my article and blog content for solving Gmail mail sending issues.
Reference :
http://www.c-sharpcorner.com/UploadFile/2a6dc5/how-to-send-a-email-using-Asp-Net-C-Sharp/
http://www.c-sharpcorner.com/blogs/smtp-server-requires-a-secure-connection1
https://rajeeshmenoth.wordpress.com/2014/07/31/how-to-send-a-email-using-asp-net-c/
http://stackoverflow.com/questions/7806944/failure-sending-mail-via-google-smtp
0
Manas Mohapatra
89
20.4k
16.7m
Sep 5 2016 7:00 AM
What is exception message you are getting in catch block. Provide details.
0
Vishal Jadav
0
1.3k
253.2k
Sep 5 2016 6:13 AM
Hi,
Can you try following code ?
public string SendEmail(string SendTo, string Subject, string MessageBody)
{
try
{
MailMessage mailmsg = new MailMessage("EMAIL ID", SendTo, Subject, MessageBody);
mailmsg.IsBodyHtml = true;
mailmsg.BodyEncoding = System.Text.Encoding.ASCII;
SmtpClient client = new SmtpClient("SMTP", 25);
client.UseDefaultCredentials = false;
//client.EnableSsl = true;
client.Credentials = new NetworkCredential("EMAIL ID", "PASSWORD");
client.Send(mailmsg);
}
catch (Exception ex)
{
return ex.ToString();
}
return "1";
}
handle event in dynamically created button in Gridview?
WPF, What is difference between Window and Page in WPF?