使用ASP.NET Web App发送电子邮件时出错

Ali*_*Net 0 asp.net smtp

我正在尝试向我的网站用户发送电子邮件(ASP.NET,VS2010),目前我正在使用我的Gmail帐户发送电子邮件,但是我收到以下错误:

ex = {"Failure sending mail."}
InnerException = {"The remote name could not be resolved: 'smtp@gmail.com'"}
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

MailMessage mailObj = new MailMessage("mygmailaccount@gmail.com", "myyahooaccount@yahoo.com", "test", "test2");
            SmtpClient SMTPServer = new SmtpClient("smtp@gmail.com");
            SMTPServer.Credentials = new System.Net.NetworkCredential("mygmailaccount", mygmailpassword);
            try
            {
                SMTPServer.Send(mailObj);
            }
            catch (Exception ex)
            {
                string a = ex.Message;
            }
Run Code Online (Sandbox Code Playgroud)

这里出了什么问题?我应该在web.config中做些什么吗?我怎样才能找到自己主机的smtp服务器?

jru*_*ell 6

smtp@gmail.com是不正确的.你可能意味着smtp.gmail.com.有关完整示例,请参阅以下问题.

通过Gmail在.NET中发送电子邮件