在.net中創建電子郵件時,是否可以在配置文件中使用「from」作爲MailMessage.From。無法訪問它。每當我嘗試引用ConfigurationManager時,我得到一個不存在的錯誤,但我引用它們,請參見下文。smtp mail設置
<mailSettings>
<smtp from="[email protected]" 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);
你爲什麼要設置'msg.From = *** ~~ **'。你最初在那裏有什麼? –