2016-04-21 62 views
0
protected void btnSubmit_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      MailMessage mailMessage = new MailMessage(); 
      mailMessage.From = new MailAddress(txtEmail.Text.ToString()); 
      mailMessage.Subject = txtSubject.Text.ToString(); 
      mailMessage.To.Add(new MailAddress("[email protected]")); 
      mailMessage.Body = txtSuggestion.Text.ToString(); 
      mailMessage.IsBodyHtml = true; 


      SmtpClient sc = new SmtpClient(); 
      sc.Host = "smtp.gmail.com"; 
      sc.Port = 587; 
      sc.Credentials = new NetworkCredential(txtEmail.Text.ToString(), txtPassword.Text.ToString()); 
      sc.EnableSsl = true; 
      sc.Send(mailMessage); 
      lblMessage.Text = "Message Sent Successfully"; 
      txtSubject.Text = ""; 
      txtEmail.Text = ""; 
      txtName.Text = ""; 
      txtSuggestion.Text = ""; 
     } 
     catch (Exception ex) 
     { 
      lblMessage.Text = ex.Message; 
     } 

    } 

这是我用来发送电子邮件的代码,但每当我尝试运行该应用程序时,出现错误。在IIS中运行应用程序时发送邮件

enter image description here

,如果有人可以帮助为什么我收到的错误,那将是巨大的。

+0

1)你可以发布调用堆栈吗? 2)使用Gmail,解决了我的问题 - https://support.google.com/accounts/answer/6010255?hl=zh-CN – devdc

+0

您是否启用了双因素身份验证? – jboeke

+0

你的'尝试阻止'得到异常,这就是为什么它显示'失败发送邮件'。删除'尝试Catch块'并发布什么原始异常是......不知道类型的异常我们必须猜测解决方案。 – KanisXXX

回答

0

你也有另外一个问题与代码是不相关的,以你的订阅一个。当设置与我们联系表单时,使用此人的电子邮件作为FROM字段将导致DMARC失败。你可以读一下关于here

另外我不明白你为什么用这个人的电子邮件地址和密码连接到Gmail。如果您要发送邮件,您应该使用自己的帐户。

相关问题