我有一个表单,允许用户向邮件列表(linq 表)上的每个人发送电子邮件。我在链接到 smtp 服务器的正确代码和语法方面遇到问题。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Web.Security;
using System.Web.Mail;
using System.Configuration;
using System.Web.Configuration;
using System.Net.Configuration;
using System.Net.Mail;
public partial class MassEmail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
mailingListClassDataContext Class = new mailingListClassDataContext();
var emaillist = from emails in Class.mailinglistMembers select emails.email;
foreach (var subcriber in emaillist)
{
MailMessage objMail = new MailMessage();
objMail.From = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a6d2c3d5d2e6d2c3d5d288c5c9cb" rel="noreferrer noopener nofollow">[email protected]</a>";
objMail.To = subcriber;
objMail.BodyFormat = MailFormat.Html ;
//The subject of the message
objMail.Subject = "test email that i hope works" ;
//he message text
objMail.Body = Editor1.Content;
//need help in this area
SmtpClient client = new SmtpClient();
SmtpClient.Send(objMail);
}
}
}
最佳答案
最好的解决方案是将 smtp 服务器详细信息放入您的 web.config
<system.net>
<mailSettings>
<smtp>
<network
host="smtp.emailhost.com"
port="25"
userName="username"
password="password" />
</smtp>
</mailSettings>
</system.net>
<system.web>
关于c# - 发送电子邮件的正确代码,asp.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3881156/