温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

C#实现QQ邮箱发送邮件

发布时间:2020-09-07 08:18:47 来源:脚本之家 阅读:174 作者:chenqiangdage 栏目:编程语言

闲着蛋疼。计划着改善公司的邮件服务。怎料公司网络封闭的太厉害了。我只能在家里利用开放点的网络来测试发送邮件;

利用qq邮箱发送到公司的企业邮箱上;

前提准备,登陆qq邮箱开启stmp服务。不开启的话没法通过代码登陆到你的邮箱;

C#实现QQ邮箱发送邮件

查询腾讯qq邮箱的smtp主机地址为:smtp.qq.com  端口是587,或者465

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
namespace mail
{
  class Program
  {
    static void Main(string[] args)
    {
      //发件人地址
      MailAddress from = new MailAddress("*********@qq.com");
      MailMessage message = new MailMessage();
      message.Body = "this is a test";
      message.IsBodyHtml = true;
      message.BodyEncoding = System.Text.Encoding.UTF8;
      //收件人地址
      message.To.Add("********bizip.com");
      message.Subject = "hello !";
      message.SubjectEncoding = System.Text.Encoding.UTF8;
      message.From = from;
      SmtpClient client = new SmtpClient();
      client.EnableSsl = true;
      client.Host = "smtp.qq.com";
      client.Port = 587;
      //邮箱账户和密码
      client.Credentials = new System.Net.NetworkCredential("mailacount","password");
      try
      {
        client.Send(message);
      }
      catch (Exception ex)
      {
        string mssage = ex.ToString();
      }     
    }
  }
}

很简单啊

vs2010测试通过!

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对亿速云的支持。如果你想了解更多相关内容请查看下面相关链接

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI