首页 > 代码库 > C#自动发送邮件
C#自动发送邮件
using System;using System.Collections.Generic;using System.Linq;using System.Net.Mail;using System.Text;using System.Threading.Tasks;namespace QQEmail{ class Program { static void Main(string[] args) { for (int i = 0; i < 50; i++) { MailMessage mymail = new MailMessage(); mymail.From = new System.Net.Mail.MailAddress("邮箱@qq.com"); mymail.To.Add("haoliu2050@163.com"); mymail.Subject = "C#自动发送邮件测试 From HaoLiu TO 1399449842@qq.com"; mymail.Body = "不好意思,我在测试程序,刚才把QQ号写错了,Sorry!"; mymail.IsBodyHtml = true; SmtpClient smtpclient = new SmtpClient(); smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpclient.Host = "smtp.qq.com"; smtpclient.Credentials = new System.Net.NetworkCredential("邮箱@qq.com", "密码"); try { smtpclient.Send(mymail); Console.WriteLine("发送成功"); } catch (Exception ex) { Console.WriteLine("发送邮件失败.请检查是否为qq邮箱,并且没有被防护软件拦截"); } } } }}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。