C#使用SMTP发送邮件实例

因为工作需要,需要使用C#发送邮件,顺便把自己写代码做个记录。以下实现简单的发送邮件功能。这边没有使用UI界面。 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net.Mail; using System.Net; using System.IO; using System.Net.Mime; namespace SmtpTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { try { //定义一个MailMessage对象 MailMessage mailmessage = new MailMessage(““, ““, “this is a test”, “yes!test!”); //from email,to email,主题,邮件内容 mailmessage.Priority = MailPriority.Normal; //邮件优先级 SmtpClient smtpClient = new SmtpClient(“smtp.163.com”, 25); //smtp地址以及端口号 smtpClient.Credentials = new NetworkCredential(“zabbix”, “xxxxxx”);//smtp用户名密码 smtpClient.EnableSsl = true; //启用ssl smtpClient.Send(mailmessage); //发送邮件 MessageBox.Show(“发送成功”); } catch (SmtpException se) //smtp错误 { MessageBox.Show(se.StatusCode.ToString()); } } } }   站点: 运维生存时间    网址:http://www.ttlsa.com/html/3472.html

转载于:https://my.oschina.net/766/blog/211189

猜你喜欢

转载自blog.csdn.net/weixin_34272308/article/details/91546587