c# 发邮件需要什么权限?

来源:百度知道 编辑:UC知道 时间:2024/05/24 18:00:56
在c# 发邮件需要什么权限?

不需要什么权限.

string sReturn = string.Empty;
MailMessage mailMsg = new MailMessage();
mailMsg.BodyFormat = MailFormat.Html;
mailMsg.To = "收件人";
mailMsg.From = "发件人";
mailMsg.Subject = "test title";
mailMsg.Body = "test content";

mailMsg.Fields.Add("smtpauthenticate", "1");
mailMsg.Fields.Add("sendusername", "你的邮箱");
mailMsg.Fields.Add("sendpassword", "你的密码");
//
SmtpMail.SmtpServer ="smtp.你邮箱的服务器.com";//smpt服务器
try
{
SmtpMail.Send(mailMsg);
Response.Write("ok");
}
catch (Exception err)
{

Response.Write(err.Message);
}

只要你使用的邮件服务器能通过你的身份验证就可以

如果利用的是公用SMTP服务器的话,一般情况下,需要该服务器的用户名,密码。
有的服务器需要你的发件人的邮箱地址和服务器地址相匹配,比如smtp.163.com,你的邮箱地址就得是xx@163.com。
有的