Hi,
I have create web application send mail. i use this code
con.Open();
com = new SqlCommand("select mailid,password='" + TextBox2.Text + "' from registration where userid='" + TextBox1.Text + "'", con);
dr = com.ExecuteReader();
if (dr.Read())
{
mid = dr["mailid"].ToString();
var fromAddress = new MailAddress("[email protected]", "Cloud Storage");
var toAddress = new MailAddress(mid, "Cloud Storage");
const string fromPassword = "pa$$word123";
const string subject = "Verification Code";
int n = _r.Next();
body = n.ToString();
Session["msg"] = body.ToString();
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
//smtp.Send(message);
}
Session["Username"] = TextBox1.Text.ToString();
Response.Redirect ("Verification.aspx");
}
else
{
Response.Write("Invalid Login");
}
but error at not remote server (sending failed) so how to set smtp server
Loading
shubhangi khandalePosted Apr 13, 2012, 7:47 AM
SenthilkumarPosted Apr 13, 2012, 7:32 AM
check it out here...
http://support.microsoft.com/kb/842242
shubhangi khandalePosted Apr 13, 2012, 7:25 AM
Keyur NarkhiPosted Apr 13, 2012, 7:23 AM
Try to use following code
Imports System.Net.Mail
Protected Sub btnSendEmail_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim mail As MailMessage = New MailMessage()
mail.To.Add("[email protected]")
mail.From = New MailAddress("[email protected]")
mail.Subject = "Email using Gmail"
String Body = "Sending mail using Gmail's SMTP in ASP.NET"
mail.Body = Body
mail.IsBodyHtml = True
Dim smtp As SmtpClient = New SmtpClient()
smtp.Host = "smtp.gmail.com"
smtp.Credentials = New System.Net.NetworkCredential
("[email protected]","password")
smtp.EnableSsl = True smtp.Port = 587 smtp.EnableSsl = true
smtp.Send(mail)
End Sub
SenthilkumarPosted Apr 13, 2012, 7:21 AM
Make sure that you are using the port 587 and it is not blocked by the firewall.
And also enable the ssl.
shubhangi khandalePosted Apr 13, 2012, 7:18 AM
SenthilkumarPosted Apr 13, 2012, 7:12 AM
At the same time you try to ping that server from the local.
There are some examples articles.
http://weblogs.asp.net/jalpeshpvadgama/archive/2010/12/29/sending-mail-with-gmail-account-using-system-net-mail-in-asp-net.aspx
http://www.codeproject.com/Articles/26971/Sending-E-mail-using-ASP-net-through-Gmail-account
http://www.shabdar.org/asp-net/111-send-email-from-your-gmail-account-using-aspnet-and-c.html
Keyur NarkhiPosted Apr 13, 2012, 7:08 AM
Try to use
Smtp.EnableSsl = false;
thanks