问题
I am about to give up debugging SMTP servers to send email... My code is the following
SmtpClient mailClient = new SmtpClient("plus.smtp.mail.yahoo.com", 465);
mailClient.EnableSsl = true;
MailMessage message = new MailMessage();
message.To.Add("aditya15417@hotmail.com");
message.Subject = "permias-tucson-contact-us";
mailClient.Credentials = new NetworkCredential("myemail@yahoo.com", "mypassword");
MailAddress fromAddress = new MailAddress(Email.Text, Name.Text);
message.From = fromAddress;
mailClient.Send(message);
回答1:
You need to pass login credentials:
mailClient.Credentials = new NetworkCredential(Email.Text, password)
回答2:
Here's a full working example:
public class Program
{
static void Main(string[] args)
{
using (var client = new SmtpClient("smtp.mail.yahoo.com", 587))
{
client.Credentials = new NetworkCredential("youraccount@yahoo.com", "secret");
var mail = new MailMessage();
mail.From = new MailAddress("youraccount@yahoo.com");
mail.To.Add("destaccount@gmail.com");
mail.Subject = "Test mail";
mail.Body = "test body";
client.Send(mail);
}
}
}
Make sure you replace your account and password.
来源:https://stackoverflow.com/questions/2575978/an-existing-connection-was-forcibly-closed-by-the-remote-host-in-smtp-client