问一个关于发送Email的问题
MailMessage msg = new MailMessage();
msg.To.Add(“收件人心想”);
msg.From = new MailAddress( "发件人邮箱 ", "发件人 ", System.Text.Encoding.UTF8);
msg.Subject = "主题 ";
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = “内容”;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = false;
msg.Priority = MailPriority.High;
//Add the Creddentials
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential( "用户名 ", "密码 ");
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
client.Host = "stmp.gmail.com ";
//client.EnableSsl = true;
client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
object userState = msg;
try
{
//you can also call client.Send(msg)
client.Send(msg);
}
catch (System.Net.Mail.SmtpException ex)
{
MessageBox.Show(ex.Message, "Send Mail Error ");
}
我这样写有什么问题吗?为什么发送不了?