error sending email using ASP.NET web app

╄→гoц情女王★ 提交于 2019-12-13 20:19:57

问题


I'm trying to send email to my site users (ASP.NET, VS2010), currently I'm using my gmail account for sending email, but I'm getting the following error:

ex = {"Failure sending mail."}
InnerException = {"The remote name could not be resolved: 'smtp@gmail.com'"}

it is my code:

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;
            }

what is going wrong here? should I do something in my web.config? how can I find smtp server of my own host?


回答1:


smtp@gmail.com is incorrect. You probably meant smtp.gmail.com. See the following question for a complete example.

Sending email in .NET through Gmail




回答2:


you did not set gmail parameters correctly:

SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
    smtpClient.EnableSsl = true;
    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtpClient.Credentials = new NetworkCredential("myGmailAcconut@gmail.com", "password");


来源:https://stackoverflow.com/questions/9313047/error-sending-email-using-asp-net-web-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!