2

我试图在 asp.net c# 上email使用发送,但我不断收到此错误:gmail account

连接尝试失败,因为连接方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应 [2607:f8b0:400c:c01::6c]:587

我尝试了来自不同资源的不同代码,但它们都没有与我的项目一起使用更多我已经尝试了这些步骤但仍然无法正常工作:

  1. 在 VS 2012 服务器和 localhost (iis 7) 上尝试端口 25、465、587。
  2. 防火墙设置为关闭,防病毒设置为关闭。
  3. 以管理员身份启动 Visual Studio。

请,谁能告诉我这个错误背后的原因是什么。如果有可能改变一些东西,我应该从哪里开始..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default6 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var myMailMessage = new System.Net.Mail.MailMessage();
        myMailMessage.From = new System.Net.Mail.MailAddress("serveremail@gmail.com");
        myMailMessage.To.Add("youremail@yahoo.com");// Mail would be sent to this address
        myMailMessage.Subject = "Feedback Form";
        myMailMessage.Body = "Hello";

        var smtpServer = new System.Net.Mail.SmtpClient("smtp.gmail.com");
        smtpServer.Port =587;
        smtpServer.Credentials = new System.Net.NetworkCredential("serveremail@gmail.com", "**YOURPASSWORD**");
        smtpServer.EnableSsl = true;
        smtpServer.Send(MyMailMessage);

        Response.Redirect("Default.aspx");
    }
}
4

2 回答 2

2

试试这个,
添加命名空间

系统网;system.net.mail;

 protected void Button1_Click(object sender, EventArgs e)
    {
        MailMessage MyMailMessage = new MailMessage();

        MyMailMessage.From = new MailAddress("from");

        MyMailMessage.To.Add("to");

        MyMailMessage.Subject = "Feedback Form";

        MyMailMessage.Body = "This is the test message from xx for testing mail send";

        MyMailMessage.IsBodyHtml = true;

        SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com");

        SMTPServer.Port = 587;

        SMTPServer.Credentials = new System.Net.NetworkCredential("username","password");

        SMTPServer.EnableSsl = true;

        try
        {

            SMTPServer.Send(MyMailMessage);

           //Response.Redirect("Thankyou.aspx");

        }

        catch (Exception ex)
        {



        }
于 2013-04-02T12:10:30.837 回答
0

你可以试试这个:

 MailMessage mail = new MailMessage();
 mail.Subject = "Your Subject";
 mail.From = new MailAddress("senderMailAddress");
 mail.To.Add("ReceiverMailAddress");
 mail.Body = "Hello! your mail content goes here...";
 mail.IsBodyHtml = true;

 SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
 smtp.EnableSsl = true;
 NetworkCredential netCre = new NetworkCredential("SenderMailAddress","SenderPassword" );
 smtp.Credentials = netCre;

 try
  {
   smtp.Send(mail);                
  }
  catch (Exception ex)
  {        
  }
于 2013-03-22T07:03:41.253 回答