在 .net 中创建电子邮件时,是否可以将配置文件中的“发件人”用作 MailMessage.From。无法访问它。每当我尝试引用 ConfigurationManager 时,我都会收到一个不存在的错误,但我正在引用它们,见下文。
<mailSettings>
<smtp from="test@test.org" deliveryMethod="Network">
<network host="smtpsend" defaultCredentials="true"/>
</smtp>
</mailSettings>
using System.Net.Mail;
using System.Net;
using System.Configuration;
using System.Net.Configuration;
MailMessage msg = new MailMessage();
msg.From = ***~~**
msg.Subject = string.Format(subject);
msg.IsBodyHtml = true;
msg.Body = body;
msg.Priority = MailPriority.Normal;
msg.To.Add("me");
SmtpClient client = new SmtpClient();
client.Send(msg);