110,571
社区成员
发帖
与我相关
我的任务
分享
MailMessage mmsg = new MailMessage();
string strReadFilePath = @"D:\三维GIS天下.txt";
StreamReader srReadFile = new StreamReader(strReadFilePath);
// 读取流直至文件末尾结束
while (!srReadFile.EndOfStream)
{
string strReadLine = srReadFile.ReadLine(); //读取每行数据
mmsg.To.Add(strReadLine);//收件人,可多人
//mmsg.Bcc.Add(strReadLine);
}
// 关闭读取流文件
srReadFile.Close();
mmsg.From = new MailAddress("zhanghao@163.com", "", System.Text.Encoding.UTF8);
SmtpClient client = new SmtpClient("smtp.163.com",25); //设置邮件协议
client.UseDefaultCredentials = false;//这一句得写前面
client.DeliveryMethod = SmtpDeliveryMethod.Network; //通过网络发送到Smtp服务器
client.Credentials = new NetworkCredential("zhanghao", "mima"); //通过用户名和密码 认证
mmsg.Subject = "开会内容"; //邮件主题
mmsg.SubjectEncoding = Encoding.UTF8; //主题编码
mmsg.Body = zw.Text;
mmsg.BodyEncoding = Encoding.UTF8; //正文编码
mmsg.IsBodyHtml = true; //设置为HTML格式
//client.Timeout = 5000;
mmsg.Priority = MailPriority.Normal; //优先级
mmsg.Attachments.Add(new Attachment("F:\\temp\\image.rar"));
try
{
client.Send(mmsg);
MessageBox.Show("邮件已发成功");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}