ASP.net MVC发送邮件 [英] ASP.net MVC Sending Mail

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

问题描述

这是我发送邮件的代码(测试代码):

This is my code to send mail (test code):

//sending mail
var message = new System.Net.Mail.MailMessage();
message.From = new MailAddress("J2v@gmail.com");
message.To.Add(model.Mailag);
message.Subject = "Valdation d'inscription";
message.Body = "Votre inscription a été valide voici vos cordonne de conexion ID user : "+model.Idag+" Password : "+user.password;
var client = new  System.Net.Mail.SmtpClient
{
    Host = "smtp.gmail.com",
    Port = 587,
    EnableSsl = true,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential("", "")
};
client.Send(message);

尝试时出现此错误:

SMTP服务器需要安全的连接,否则您未连接.服务器响应为:5.5.1需要身份验证.了解更多信息

SMTP server require secured connexion or you are not connected. Server response was :5.5.1 Authentication Required. Learn more at

在此行上: client.Send(message);

推荐答案

依靠GMAIL时,请使用以下设置:

Use the following settings when relying to GMAIL:

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.UseDefaultCredentials = false;
var credentials = System.Net.NetworkCredential("yourid@gmail.com", "yourpwd");
smtp.Credentials = credentials;
smtp.EnableSsl = true;
smtp.Port = 587;

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆