|
Forums » .NET » ASP.NET »
Posted Date: 09 Jun 2012 Posted By:: Vijay Khanjode Member Level: Silver Member Rank: 1644 Points: 5
Responses:
8
|
hi, i want to send email using my application below code was working before couple of months but right now this is not working what is problem with this code please suggest me.
===============================
protected void BtnSend_Click(object sender, EventArgs e) { string str = SendMail(Txtfrom.Text,TxtTo.Text, TxtSubject.Text, TxtBody.Text);
Response.Write(str); }
public string SendMail(string from, string to, string subject, string body) {
// Building the Message MailMessage msg = new MailMessage(); msg.To.Add(to); msg.From = new MailAddress(from, "Name", System.Text.Encoding.UTF8); msg.Subject = subject; msg.SubjectEncoding = System.Text.Encoding.UTF8; msg.Body = body; msg.BodyEncoding = System.Text.Encoding.UTF8; msg.IsBodyHtml = true; msg.Priority = MailPriority.High;
// Smtp configuration SmtpClient client = new SmtpClient(); client.Credentials = new System.Net.NetworkCredential("my@gmail.com", "myGmailpassword"); client.Port = 465; //25 or use 587 or 465 client.Host = "smtp.gmail.com"; client.EnableSsl = true; try { client.Send(msg); return "Send Mail Successfully"; } catch (Exception ex) { return ex.Message; } }
|
Responses
|
#674632 Author: Ravindra Gaurana Member Level: Gold Member Rank: 178 Date: 09/Jun/2012 Rating:  Points: 2 | Hi Vijay
May be some anti virus firewall stooping it check with disabling/off firewall.
For More Details Refer this link... http://social.msdn.microsoft.com/forums/en/netfxnetcom/thread/a75533eb-131b-4ff3-a3b2-b6df87c25cc8/
Thanks & Regards Ravindra Gaurana Dotnetravindera@gmail.com Catch Me dotnetspider
| #674642 Author: Ravindran Member Level: Diamond Member Rank: 3 Date: 09/Jun/2012 Rating:  Points: 3 | Hi,
Did you can any error during send? if yes then you please tell what error message is return in catch block. Otherwise try it new gmail id to test, change new email id in the below line instead of old one
client.Credentials = new System.Net.NetworkCredential("my@gmail.com", "myGmailpassword");
Regards N.Ravindran Your Hard work never fails
| #674705 Author: Asheej T K Member Level: Diamond Member Rank: 2 Date: 10/Jun/2012 Rating:  Points: 3 | Hi,
If it worked earlier then I doubt problem is with code. Check your system event viewer and see if there is any error logging there while sending mail. Also make sure firewall is not blocking you to send the mail. Try to debug the code locally and make sure the execution is reaching the lineclient.Send(msg);
Regards, Asheej T K Microsoft MVP[ASP.NET/IIS] DotNetSpider MVM
Dotnet Galaxy
| #674726 Author: Anil Kumar Pandey Member Level: Platinum Member Rank: 1 Date: 10/Jun/2012 Rating:  Points: 2 | There must be issue in the SMTP setting.
make sure the SMTP server is configured correctly or else debug the code to check the actual error.
Thanks & Regards Anil Kumar Pandey Microsoft MVP, DNS MVM
| #674748 Author: sudhajosyula Member Level: Gold Member Rank: 46 Date: 10/Jun/2012 Rating:  Points: 2 | The failure is caused due to SMTP Server is not configured properly at your system.Kindly check first whether it is configured properly or not.After check if any firewall are causing the issue.Beside these,the code will definitely work as per intended.. :)
| #674938 Author: Paritosh Mohapatra Member Level: Diamond Member Rank: 6 Date: 11/Jun/2012 Rating:  Points: 2 | For sending mail using a Mail Client, you need 4 things:
1) SMTP Server. - e.g. GMail uses smtp.gmail.com 2) Port Number. - Usually Port 25 is used to send mail. 3) Sender Email ID. 4) Sender Password.
If you are using Yahoo Mail, then use default Port Number 25 without SSL. If you are using Yahoo Mail Plus use Port Number 465 with SSL enabled. The SMTP address used by yahoo is smtp.mail.yahoo.com.
To send bulk mail to a group of users, you can add multiple recipient in to, cc or bcc, separating each of them using ";" e.g. "a1@gmail.com;b1@gmail.com;c1@gmail.com".
Please check the following code to send mail:
protected void Button1_Click(object sender, EventArgs e) { string str = SendMail("yourid@gmail.com", "receiver@domain.com", "subject", "body"); Response.Write(str); }
public string SendMail(string from, string to, string subject, string body) {
// Building the Message MailMessage msg = new MailMessage(); msg.To.Add(to); msg.From = new MailAddress(from, "Name", System.Text.Encoding.UTF8); msg.Subject = subject; msg.SubjectEncoding = System.Text.Encoding.UTF8; msg.Body = body; msg.BodyEncoding = System.Text.Encoding.UTF8; msg.IsBodyHtml = true; msg.Priority = MailPriority.High;
// Smtp configuration SmtpClient client = new SmtpClient(); client.Credentials = new System.Net.NetworkCredential("yourid@gmail.com", "yourpassword"); client.Port = 25; //25 or use 587 or 465 client.Host = "smtp.gmail.com"; client.EnableSsl = true; try { client.Send(msg); return "Send Mail Successfully"; } catch (Exception ex) { return ex.Message; } }
Thanks & Regards Paritosh Mohapatra Microsoft MVP (ASP.Net/IIS) DotNetSpider MVM
| #676338 Author: Vijay Khanjode Member Level: Silver Member Rank: 1644 Date: 19/Jun/2012 Rating:  Points: 1 | thanks @ N.Ravindran when i send mail then "The operation has timed out." message is fired,
| #676411 Author: Asheej T K Member Level: Diamond Member Rank: 2 Date: 20/Jun/2012 Rating:  Points: 2 | Hi,
The operation has timed out error normally occurs when you are not able to connect SMTP server. So make sure your anti virus or firewall is not blocking to connect SMTP server.
Regards, Asheej T K Microsoft MVP[ASP.NET/IIS] DotNetSpider MVM
Dotnet Galaxy
|
|
| Post Reply |
|
|
|
 | | This thread is locked for new responses. Please post your comments and questions as a separate thread. If required, refer to the URL of this page in your new post. |
|
|
|
|
 Follow us on Twitter: https://twitter.com/dotnetspider
|
|