Пример #1
0
        static void Main(string[] args)
        {
            //普通测试
            SmtpMailClient client = new SmtpMailClient("smtp.163.com", 25, true, "XXX", "XXX");
            client.Timeout = 18000;
            MailMessage msg = new MailMessage();
            msg.From = new MailAccount("*****@*****.**", "janky");
            msg.AddTo(new MailAccount("*****@*****.**", "测试1"));
            msg.AddTo(new MailAccount("*****@*****.**"));
            msg.AddCC(new MailAccount("*****@*****.**"));
            //msg.AddCC(new MailAccount("*****@*****.**"));
            msg.MailContent = "<p>IHU 发信IP因发送垃圾邮件或存在异常的连接行为,被暂时挂起。请检测发信IP在历史上的发信情况和发信程序是否存在异常;</p><a href='http://163.com'>163 邮箱</a>";
            msg.Subject = "测试";
            msg.IsHtml = true;
            client.Send(msg);

            //附件测试
            client = new SmtpMailClient("smtp.163.com", 25, true, "XXX", "XXX");
            client.Timeout = 18000;
            msg = new MailMessage();
            msg.From = new MailAccount("*****@*****.**", "janky");
            msg.AddTo(new MailAccount("*****@*****.**", "测试1"));
            msg.AddTo(new MailAccount("*****@*****.**"));
            msg.AddCC(new MailAccount("*****@*****.**"));
            msg.MailContent = "<img src='cid:test1234' /><p>IHU 发信IP因发送垃圾邮件或存在异常的连接行为,被暂时挂起。请检测发信IP在历史上的发信情况和发信程序是否存在异常;</p><a href='http://163.com'>163 邮箱</a>";
            msg.Subject = "测试";
            msg.IsHtml = true;

            msg.AddAttachment(@"c:\test\test.txt");
            msg.AddAttachment(@"c:\test\taiwan.jpg", "test1234"); //这里是content-id
            msg.AddAttachment(@"c:\test\filechktool.rar");
            client.SendAsync(msg);

            //ssl 测试
            SmtpServerInfo info = new SmtpServerInfo("smtp.gmail.com", 465, true, "XXX", "janky,.XXX");
            info.EnableSsl = true;
            client = new SmtpMailClient(info);
            client.Timeout = 18000;
            msg = new MailMessage();
            msg.From = new MailAccount("*****@*****.**", "系统");
            msg.AddTo(new MailAccount("*****@*****.**", "测试1"));
            msg.AddTo(new MailAccount("*****@*****.**"));
            msg.AddCC(new MailAccount("*****@*****.**"));
            msg.MailContent = "<p>IHU 发信IP因发送垃圾邮件或存在异常的连接行为,被暂时挂起。请检测发信IP在历史上的发信情况和发信程序是否存在异常;</p><a href='http://163.com'>163 邮箱</a>";
            msg.Subject = "测试";
            msg.IsHtml = true;
            client.Send(msg);
            Console.ReadKey();
        }
Пример #2
0
 public SmtpMailClient(SmtpServerInfo serverInfo)
 {
     this.ServerInfo = serverInfo;
 }
Пример #3
0
 /// <summary>
 /// 验证服务器信息
 /// </summary>
 /// <param name="serverInfo"></param>
 private void CheckStmpServerInfo(SmtpServerInfo serverInfo)
 {
     if (serverInfo == null)
         throw new InfoMissingException("Smtp Server Info");
     if (serverInfo.SmtpServer == null || serverInfo.SmtpServer.Length < 6)
         throw new InfoMissingException("Smtp Server");
     if (serverInfo.IsSendAuth)
     {
         if (serverInfo.Account == null || serverInfo.Account.Length < 1)
             throw new InfoMissingException("Account");
         if (serverInfo.Password == null || serverInfo.Password.Length < 1)
             throw new InfoMissingException("Password");
     }
 }