发现注册后发送邮件有困难 [英] Finding difficulty with sending mail after registration
本文介绍了发现注册后发送邮件有困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
i需要你的支持人员,因为下面的发送邮件部分代码不能正常工作,因为我尝试了很多次但是我没有收到任何邮件,所以,请你帮我修复这个案例,没有任何错误信息,但没有任何电子邮件进入我的收件箱。 (admin@gmail.com只是一个示例,此电子邮件假定为发件人,将在emailbox.Text中写入的电子邮件为To(我的意思是用户))
Hi
i need your support guys as the below code of sending mail part is not working as i am trying many time but i haven't receive any mail, so could you please help me to fix this case there is no any error message but no any email is coming to my inbox. ("admin@gmail.com is just a sample and this email is suppose to be "From" and the email which will be written in "emailbox.Text" is "To (i mean user)")
protected void btnSave_Click(object sender, EventArgs e)
{
HttpCookie cookie = Request.Cookies.Get("Location");
string Location = string.Empty;
SqlConnection cn = new SqlConnection(sc);
SqlCommand cmd = new SqlCommand();
Location = cookie.Value;
if (CheckBox1.Checked)
{
string sqlstatment = @"INSERT INTO UserInfo (UID, FN, LN, Password, RePass, Email,Country, State,City, Post, Img, Logo,RegDate,Address, UsrType,BizCateg,BizSubCateg) VALUES
(@UID,@FN,@LN,@Password,@RePass,@Email,@Country,@State,@City,@Post,@Img,@Logo,@RegDate,@Address,@UsrType,@BizCateg,@BizSubCateg)";
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlstatment;
//Insert the parameters first
cmd.Parameters.AddWithValue("@UID", UsrNme.Text);
cmd.Parameters.AddWithValue("@FN", fnbox.Text);
cmd.Parameters.AddWithValue("@LN", lnamebox.Text);
cmd.Parameters.AddWithValue("@Password", passtxtbx1.Text);
cmd.Parameters.AddWithValue("@RePass", passtxtbx2.Text);
cmd.Parameters.AddWithValue("@Email", emailbox.Text);
cmd.Parameters.AddWithValue("@Country", cookie.Value);
cmd.Parameters.AddWithValue("@State", statedrdolst.SelectedItem.Text);
cmd.Parameters.AddWithValue("@City", citiesdrdolst.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Post", postbox.Text);
cmd.Parameters.AddWithValue("@Logo", logoFileUpload.FileName);
cmd.Parameters.AddWithValue("@Address", regaddrstxtbx.Text);
cmd.Parameters.AddWithValue("@UsrType", UsrTypeDrDo.SelectedItem.Text);
//cmd.Parameters.AddWithValue("@BizCateg", BizCateDDL.SelectedItem.Text);
//cmd.Parameters.AddWithValue("@BizSubCateg", SubCatBizDDL.SelectedItem.Text);
if (BizCateDDL.SelectedIndex < 0)
cmd.Parameters.AddWithValue("@BizCateg", DBNull.Value);
else
cmd.Parameters.AddWithValue("@BizCateg", BizCateDDL.SelectedItem.Value);
if (SubCatBizDDL.SelectedIndex < 0)
cmd.Parameters.AddWithValue("@BizSubCateg", DBNull.Value);
else
cmd.Parameters.AddWithValue("@BizSubCateg", SubCatBizDDL.SelectedItem.Value);
cmd.Parameters.AddWithValue("@RegDate", DateTime.Now);
if (!string.IsNullOrEmpty(UsrNme.Text))
{
Lblcheckusername.Text = "User Name Already Exist";
Lblcheckusername.ForeColor = System.Drawing.Color.Red;
}
else
{
Lblcheckusername.Text = "User Name Available";
Lblcheckusername.ForeColor = System.Drawing.Color.Green;
}
string imgnouser = "/images/general/nouser.jpg";
if (persimgFileUpload1.HasFile)
{
cmd.Parameters.AddWithValue("@Img", persimgFileUpload1.FileName);
persimgFileUpload1.SaveAs(Server.MapPath("~/images/users/" + persimgFileUpload1.FileName));
}
else
{
cmd.Parameters.AddWithValue("@Img", imgnouser);
}
if (logoFileUpload.HasFile)
{
logoFileUpload.SaveAs(Server.MapPath("~/images/Logos/" + logoFileUpload.FileName));
}
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ad.SelectCommand = cmd;
ad.Fill(ds);
Session["UsrNme"] = UsrNme.Text;
const string username = "admin@gmail.com";
const string password = "admin111";
SmtpClient smtpclient = new SmtpClient();
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
MailAddress fromaddress = new MailAddress("admin@gmail.com");
smtpclient.Host = "smtp.gmail.com";
smtpclient.Port = 587;
mail.From = fromaddress;
mail.To.Add(emailbox.Text);
mail.Subject = ("Test Subject");
mail.IsBodyHtml = true;
mail.Body = "This is test Mail";
smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpclient.Credentials = new System.Net.NetworkCredential(username, password);
try
{
smtpclient.Send(mail);
Response.Write("Email Has been sent successfully.");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
Response.Redirect("User panel.aspx");
}
else
{
Label1.Text = "please check the box to continue";
}
}
推荐答案
请浏览我的博客你会得到发送电子邮件的工作代码。
http://sameeakhtar786.blogspot.in/ [ ^ ]
Please go through my blog you will get a working code to send email.
http://sameeakhtar786.blogspot.in/[^]
无事可做!只需致电您要发送消息的方法。
示例 - 首先更改方法中的设置并调用如下方法
受保护的void btnsend_click(--- ----------------)
{
//在这里做你的东西
SendMail( );
}
Nothing to do !!!Just call the method from where you want to send the message.
example--First change the settings in the method and call the method as below
Protected void btnsend_click(-------------------)
{
//do your stuff here
SendMail();
}
这篇关于发现注册后发送邮件有困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文