c# Smtp方式发电子邮件正确代码

作者:小鱼的互联网观察 发布时间:May 20, 2010 分类:技术

System.Net.Mail.SmtpClient client = new SmtpClient();
            client.Host = "smtp.163.com";
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential("你的163用户名", "*****");
           //星号改成自己邮箱的密码            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            System.Net.Mail.MailMessage message = new MailMessage("你的163邮箱地址", "收件人邮箱地址");
            message.Subject = "测试";
            message.Body = "用自己写的软件发的邮件!";
            message.BodyEncoding = System.Text.Encoding.UTF8;
            message.IsBodyHtml = true;
           //添加附件            Attachment data = new Attachment(@"附件地址如:e:\a.jpg", System.Net.Mime.MediaTypeNames.Application.Octet);
            message.Attachments.Add(data);

            try
            {
                client.Send(message);
                MessageBox.Show("Email successfully send.");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Send Email Failed." + ex.ToString());
            }

MailToDemo.zip

转自:http://www.cnblogs.com/tuyile006/archive/2007/06/15/784446.html

标签: c# Smtp方式发电子邮件正确代码

互联网观察
c# Smtp方式发电子邮件正确代码
本文地址:https://tianmeng.org/archives/242/

相关文章

  • 无相关文章
文档信息

当前暂无评论 »

网站地图 京ICP证030173号