我正在尝试创建联系表单以发送电子邮件(from
并将to
来自用户界面):
try {
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("fromadd");
mail.To.Add("toadd");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("username","password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("mail Send");
}
catch (Exception ex) {
MessageBox.Show(ex.ToString());
}
这仅适用于 Gmail - 但是,我想让它适用于任何电子邮件提供商 - 我将如何解决这个问题?