Error in Sending Mail [Resolved]

Posted by Sushant under ASP.NET on 6/26/2013 | Points: 10 | Views : 786 | Status : [Member] | Replies : 2
protected void btnSubmit_Click(object sender, EventArgs e)
{
string mailbody = "";
mailbody = "Someone with the following details sent an enquiry for <b>Dream World Properties</b><br/>";
mailbody += "Name : <b>" + txtName.Text + "</b><br/>";
mailbody += "Contact No. : <b>" + txtMobile.Text + "</b><br/>";
mailbody += "Email : <b>" + txtEmail.Text + "</b><br/>";
mailbody += "City : <b> " + txtCity.Text + "</b><br/>";
if (txtMsg.Text.Length > 0)
mailbody += "Message : <b>" + txtMsg.Text + "</b><br/>";
else
mailbody += "Message : <b>No Message !</b>";
MailAddress MailTo = new MailAddress(ConfigurationManager.AppSettings["mailto"].ToString());
MailAddress MailFrom = new MailAddress(ConfigurationManager.AppSettings["mailfrom"].ToString());
SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["smtphost"].ToString());
smtp.Port = 465;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("information@dreamworldproperties.in", "information123");
smtp.UseDefaultCredentials = true;
MailMessage message = new MailMessage(MailFrom, MailTo);
message.Subject = "Dream World Properties" + '(' + DateTime.Now.ToString() + ')';
message.Body = mailbody;
message.IsBodyHtml = true;
try
{
if (Session["CAPTCHA"].ToString().Equals(txtcapcha.Text))
{
InsertConatctUsFeedback();
lblcapcha.Text = "Thanks For Your Message!";
txtcapcha.Text = "";
smtp.Send(message);
clear();

}
else
{
lblcapcha.Text = "Wrong Input";
txtcapcha.Text = "";
}
}
catch (Exception ex)
{
lblMsg.Text = ex.Message.ToString();
}
finally
{

}
}
public string ipTracker()
{
string ip = "";
ip = HttpContext.Current.Request.ServerVariables.Get("HTTP_X_FORWARDED_FOR");
if (!string.IsNullOrEmpty(ip))
{
string[] ipRange = ip.Split(',');
int le = ipRange.Length - 1;
ip = ipRange[le];
}
else
{
ip = HttpContext.Current.Request.ServerVariables.Get("REMOTE_ADDR");

}
return ip.ToString();
}
---------------------------------------web config File-----------------------------------------------------
<appSettings>
<add key="ForLogin" value="Login.aspx"/>
<add key="mailto" value="sushant@nextgensolution.in"/>
<add key="mailfrom" value="information@dreamworldproperties.in"/>
<add key="mailpass" value="information123"/>
<add key="smtphost" value="smtp.gmail.com"/>
<add key="domainid" value="1"/>
<!--<add key="dbcon1" value="Data Source=**********.db.*********.hostedresource.com; Initial Catalog=*************; UID=**********; pwd='************';Min Pool Size=10;Max Pool Size=200;Connect Timeout=200;Load Balance Timeout=200;"/>-->
</appSettings>

----------------Error ----------------------------
Failure sending mail.


plz help

Sushat


Responses

Posted by: perfectchourasia-9163 on: 6/27/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
http://www.aspnetcodes.com/2011/05/send-mail-in-aspnet.html

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Sushant, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: aswinialuri-19361 on: 6/26/2013 [Member] Starter | Points: 25

Up
0
Down
hi sushant ,

Try this i hope it will help you
namespace
using system.net.mail;

protected void Button1_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage("aswinialuri@gmail.com", txt1_to.Text);

msg.IsBodyHtml = true;
msg.Subject=txt_sub.Text.ToString();
msg.Body=txt_body.Text.ToString();
NetworkCredential nc = new NetworkCredential("aswinialuri@gmail.com", "@@@@@@@@pwd@");
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = nc;
smtp.Send(msg);

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Sushant, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response