我正在尝试使用 CDO 发送电子邮件。我想将设置更改为始终从具有特定用户、传递和来自的特定 smtp 服务器发送。但是,当我尝试更改配置时,我收到一个错误,即数据是只读的。您如何更改消息的配置?
Message msg = new Message();
IConfiguration config = msg.Configuration;
config.Fields["smtpserver"] = "SERVER";
msg.Subject = "TEST";
msg.From = "FROM@FROM.com";
msg.To = "TO@TO.com";
msg.TextBody = "TESTING";
msg.Send();
我尝试过使用System.Net.Mail
,但这似乎被防火墙阻止了。我收到异常消息Unable to connect to the remote server : No connection could be made because the target machine actively refused it {IP}:67
MailMessage msg = new MailMessage();
msg.Subject = "TESTING";
msg.From = new MailAddress("MYMAIL@MYMAIL.org");
msg.To.Add(new System.Net.Mail.MailAddress("TOMAIL@TOMAIL.org"));
msg.Body = "dubbly doo";
SmtpClient client = new SmtpClient();
client.Host = "HOST";
client.Port = 67;
client.EnableSsl = true;
client.Credentials = new NetworkCredential("USERNAME", "PASSWORD", "DOMAIN");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
client.Send(msg);
}
catch(SmtpException e)
{
Console.Write(e.InnerException.Message+":"+e.InnerException.InnerException.Message);
Console.ReadLine();
}