我正在尝试使用System.Net.Mail发送电子邮件c#;
但是我收到以下异常消息:
这是我的发送电子邮件代码:
MailMessage mail = new MailMessage();
smtpServer = new SmtpClient();
smtpServer.Host = "smtp.gmail.com";
mail.From = new MailAddress("example@gmail.com");
mail.To.Add(new MailAddress(textBox7.Text));
mail.Subject = "Your User ID and Password For etc company";
mail.Body = "Your ID IS:" + textBox1.Text + " Your Password Is: " +
textBox2.Text;
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential();
smtpServer.EnableSsl = true;
smtpServer.Send(mail);
MessageBox.Show("Mail Successfully Sent To " + textBox7.Text, "Message",
MessageBoxButtons.OK, MessageBoxIcon.Information);
答案 0 :(得分:0)
构造函数new MailAddress
不接受空字符串。问题很可能是您的textBox7.Text
是一个空字符串。