本文介绍了邮件发送失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 尝试 
{
如果 (Upload_image.HasFile&& Upload_sign.HasFile&& Captcha1.UserValidated)
{
int i = cmd.ExecuteNonQuery() ;
if (i > 0
{
// 成功提交表格后,将注册号码发送到用户的邮箱
SmtpClient smtpc = new SmtpClient( smtp.gmail.com);
smtpc.Port = 587 ;
smtpc.EnableSsl = true ;
smtpc.UseDefaultCredentials = false ;
string user = ajay.mukesh @ gmail.com; // < - 在此处输入您的Gmail代码
string pass = password; // < - 在此输入您的Gmail密码
string sub = 表格填写申请表:; // 您网站的主题
string msg = Webcome to http://msdotnet.co.in您的注册号是: + Label2.Text; // 邮件正文
smtpc.Credentials = 新的 NetworkCredential(用户,通行证);
MailMessage email = new MailMessage(user,TextBox6.Text,sub,msg);
email.IsBodyHtml = true ;
smtpc.Send(电子邮件);

Label1.Text = 您的表单已成功提交。立即预览,注册数字是:;
Label3.Text = null ;
}
else
{
Label1.Text = 您的表单未成功提交请稍后再试;
Label3.Text = null ;
Label2.Text = null ;
}
}
else
{
Label3.ForeColor = System.Drawing.Color.Red;
Label3.Text = 输入有效的验证码;
Label2.Text = null ;
}
}
catch (例外情况)
{
Label1.Text = ex.Message;
}
最后
{
con.Close();
}
解决方案

try
              {
                  if (Upload_image.HasFile && Upload_sign.HasFile && Captcha1.UserValidated)
                  {
                     int i = cmd.ExecuteNonQuery();
                      if (i > 0)
                      {
                          // Send Regisration number to user's mail box after submitting the form successfully
                          SmtpClient smtpc = new SmtpClient("smtp.gmail.com");
                          smtpc.Port =587;
                          smtpc.EnableSsl = true;
                          smtpc.UseDefaultCredentials = false;
                          string user = "[email protected]"; //<--Enter your gmail id here
                          string pass = "password";//<--Enter Your gmail password here
                          string sub = "Form filling Application:"; //Subject for your website
                          string msg = "Webcome to http://msdotnet.co.in Your Registration Number is: " + Label2.Text;  //Message body
                          smtpc.Credentials = new NetworkCredential(user, pass);
                          MailMessage email = new MailMessage(user, TextBox6.Text, sub, msg);
                          email.IsBodyHtml = true;
                          smtpc.Send(email);

                          Label1.Text = "Your form has been submitted successfully.Take Preview Now,Your Registration Number is: ";
                          Label3.Text = null;
                      }
                      else
                      {
                          Label1.Text = "Your form has been not submitted successfully try again later";
                          Label3.Text = null;
                          Label2.Text = null;
                      }
                  }
                  else
                  {
                      Label3.ForeColor = System.Drawing.Color.Red;
                      Label3.Text = "Enter Valid Captcha code";
                      Label2.Text = null;
                  }
              }
              catch (Exception ex)
              {
                  Label1.Text = ex.Message;
              }
              finally
              {
                  con.Close();
              }
解决方案


这篇关于邮件发送失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-02 15:47