如何使用公司的电子邮件地址(网络邮件)在C#app中发送电子邮件?我尝试了以下代码,但没有奏效。
它适用于Gmail,但不适用于网络邮件。
using System.Net;
using System.Net.Mail;
private void btnSend_Click_2(object sender, EventArgs e)
{
string from, pass;
MailMessage message = new MailMessage();
from = "london.city@COMPANY.org.uk";
pass = "PASSWORD";
message.To.Add("ABC@gmail.com");
message.Subject = "Hello my friend";
message.From = new MailAddress(from);
message.Body = "I am feeling good";
SmtpClient smtp = new SmtpClient("smtp.webmail.COMPANY.org.uk");
smtp.EnableSsl = true;
smtp.Port = 25;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(from, pass);
try
{
smtp.Send(message);
MessageBox.Show("send successfully");
}
catch (Exception et)
{
MessageBox.Show(et.Message);
}
}