我在用using System.Net.Mail;
和以下代码发送邮件
MailMessage message = new MailMessage();
SmtpClient client = new SmtpClient();
// Set the sender's address
message.From = new MailAddress("fromAddress");
// Allow multiple "To" addresses to be separated by a semi-colon
if (toAddress.Trim().Length > 0)
{
foreach (string addr in toAddress.Split(';'))
{
message.To.Add(new MailAddress(addr));
}
}
// Allow multiple "Cc" addresses to be separated by a semi-colon
if (ccAddress.Trim().Length > 0)
{
foreach (string addr in ccAddress.Split(';'))
{
message.CC.Add(new MailAddress(addr));
}
}
// Set the subject and message body text
message.Subject = subject;
message.Body = messageBody;
// Set the SMTP server to be used to send the message
client.Host = "YourMailServer";
// Send the e-mail message
client.Send(message);
对于我提供的主机client.Host = "localhost";
为此,它因错误而堕落
无法建立连接,因为目标机器主动拒绝了some_ip_address_here
当我使用client.Host = "smtp.gmail.com";
我收到以下错误
连接尝试失败,因为连接的一方在一段时间后没有正确响应,或者连接失败,因为连接的主机没有响应
我无法通过 localhost 发送邮件。请帮帮我,我是 C# 新手,请在我出错的代码中纠正我..?