找传奇、传世资源到传世资源站!

C#发送邮件实例(入门级)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

C#发送邮件实例
from clipboard
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Net;using System.Net.Mail;using System.Text;using System.Threading;using System.Windows.Forms;namespace SendEmail{ public partial class FrmMain : Form { public FrmMain() { InitializeComponent(); } private void btnSend_Click(object sender, EventArgs e) { string senderEmail = txtSenderEmail.Text.Trim(); string emailBoxPwd = txtEmailBoxPwd.Text.Trim(); string senderName = txtSenderName.Text.Trim(); string emailTitle = txtEmailTitle.Text.Trim(); string emailContent = txtEmailContent.Text.Trim(); string[] recEmail = txtRecEmail.Text.Split('\n'); for (int i = 0; i < recEmail.Length; i ) { if (SendEmail(recEmail[i], senderEmail, senderName, emailTitle, emailContent, emailBoxPwd)) { btnSend.Text = "已发送" (i 1) " / " recEmail.Length; } } btnSend.Text = "发送"; } public bool SendEmail(string recEmail, string senderEmail, string senderName, string emailTitle, string emailContent, string emailBoxPwd) { try { MailMessage msg = new MailMessage(); msg.To.Add(recEmail);//收件人地址 msg.From = new MailAddress(senderEmail, senderName);//发件人邮箱,名称 msg.Subject = emailTitle;//邮件标题 msg.SubjectEncoding = Encoding.UTF8;//标题格式为UTF8 msg.Body = emailContent;//邮件内容 msg.BodyEncoding = Encoding.UTF8;//内容格式为UTF8 SmtpClient client = new SmtpClient(); client.Host = "smtp.qq.com";//SMTP服务器地址 client.Port = 587;//SMTP端口,QQ邮箱填写587 client.EnableSsl = true;//启用SSL加密 client.Credentials = new NetworkCredential(senderEmail, emailBoxPwd);//发件人邮箱账号,密码 client.Send(msg);//发送邮件 } catch (Exception) { return false; } return true; } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复