//from是发送的邮箱地址//to是指发送的目标邮箱///subject是标题///body是发送的内容,注意相关词汇可能会导致当垃圾邮箱处理private void SendMessage(string from, string to, string subject, string body) { System.Net.Mail.MailMessage mm = null; SmtpClient Client; Client = new SmtpClient { Host = "smtp.163.com",//QQ的是smtp.qq.com Port = 25,//端口测试和QQ的都是25测试成功 DeliveryMethod = SmtpDeliveryMethod.Network }; Client.UseDefaultCredentials = false; Client.Credentials = new NetworkCredential("***@163.com", "smtp服务的密码");//在设置里面开启会有密码提示QQ同理
try { mm = new System.Net.Mail.MailMessage(from, to, subject, body); mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; mm.BodyEncoding = System.Text.Encoding.UTF8; mm.IsBodyHtml = true; Client.Send(mm); isSent = true; } catch (Exception ex) { //process ex.message } finally { mm.Dispose(); } }
时间: 2024-11-04 15:30:59