c# STMP类发送邮件

 System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient
            {
                Host = "smtp.163.com",//使用163的SMTP服务器发送邮件
                UseDefaultCredentials = true,
                DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,
                Credentials = new System.Net.NetworkCredential("ml18691355356@163.com", "lemon@198858")//163的SMTP服务器需要用163邮箱的用户名和密码作认证,如果没有需要去163申请个,
            };
            //这里假定你已经拥有了一个163邮箱的账户,用户名为abc,密码为*******
            System.Net.Mail.MailMessage Message = new System.Net.Mail.MailMessage
            {
                From = new System.Net.Mail.MailAddress("ml18691355356@163.com")//这里需要注意,163似乎有规定发信人的邮箱地址必须是163的,而且发信人的邮箱用户名必须和上面SMTP服务器认证时的用户名相同
            };
            //因为上面用的用户名abc作SMTP服务器认证,所以这里发信人的邮箱地址也应该写为abc@163.com
            Message.To.Add("393527381@qq.com");//将邮件发送给QQ邮箱
            Message.To.Add("ml18691355356@163.com");
            Message.Subject = "测试标体";
            Message.Body = "thisis my new message"; 
            Message.SubjectEncoding = System.Text.Encoding.UTF8;
            Message.BodyEncoding = System.Text.Encoding.UTF8;
            Message.Priority = System.Net.Mail.MailPriority.High;
            Message.IsBodyHtml = true;
            client.Send(Message);
        }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值