1、先开启QQ邮箱中的POP3/SMTP服务
2、代码
MailMessage myMail = new MailMessage(); //创建邮件实例对象
myMail.From = new MailAddress(""); //发送者,要和邮件服务器的验证信息对应,不能随便更改
myMail.To.Add(new MailAddress("")); //接收者
myMail.Subject = "C#发送Email"; //邮件标题
myMail.SubjectEncoding = Encoding.UTF8; //标题编码
myMail.Body = "this is a test email!"; //邮件内容
myMail.BodyEncoding = Encoding.UTF8; //邮件内容编码
myMail.IsBodyHtml = true; //邮件内容是否支持html
SmtpClient smtp = new SmtpClient(); //创建smtp实例对象
smtp.Host = "smtp.qq.com"; //邮件服务器SMTP
smtp.Port = 25; //邮件服务器端口
smtp.Credentials = new NetworkCredential("发送者邮箱账号", "密码"); //邮件服务器验证信息
smtp.Send(myMail); //发送邮件
时间: 2024-11-04 22:03:46