示例#1
0
        public void SendEmailBy163(EmailData text)
        {
            SmtpClient smtp = new SmtpClient(EmailClient);

            smtp.Port = 25;
            if (EmailClientPort.HasValue)
            {
                smtp.Port = EmailClientPort.Value;
            }
            smtp.EnableSsl   = true;
            smtp.Credentials = new System.Net.NetworkCredential(EmailId, EmailKey);
            MailMessage msg = new MailMessage();

            msg.From = new MailAddress(EmailId);
            msg.To.Add(text.EmailTo);
            if (text.Mailer != null)
            {
                foreach (var item in text.Mailer)
                {//抄送人
                    msg.To.Add(item);
                }
            }
            msg.Subject         = text.EmailSubject; //邮件标题
            msg.SubjectEncoding = Encoding.UTF8;
            msg.Body            = text.EmailBody;    //邮件内容
            msg.BodyEncoding    = Encoding.UTF8;
            msg.IsBodyHtml      = true;
            msg.Priority        = MailPriority.High;//邮件优先级
            Guid gid = Guid.NewGuid();

            smtp.Send(msg);

            /*
             * smtp.SendAsync(msg,gid );
             * 现在无法开始异步操作。异步操作只能在异步处理程序或模块中开始,或在页生存期中的特定事件过程中开始。如果此异常在执行 Page 时发生,请确保 Page 标记为 <%@ Page Async="true" %>。此异常也可能表明试图调用“异步无效”方法,在 ASP.NET 请求处理内一般不支持这种方法。相反,该异步方法应该返回一个任务,而调用方应该等待该任务。
             */
        }
示例#2
0
        public void SendEmailBy163(EmailData text)
        {
            SmtpClient client = new SmtpClient(this.EmailClient)
            {
                Port = 0x19
            };

            if (this.EmailClientPort.HasValue)
            {
                client.Port = this.EmailClientPort.Value;
            }
            client.EnableSsl   = true;
            client.Credentials = new NetworkCredential(this.EmailId, this.EmailKey);
            MailMessage message = new MailMessage
            {
                From = new MailAddress(this.EmailId)
            };

            message.To.Add(text.EmailTo);
            if (text.Mailer != null)
            {
                foreach (string str in text.Mailer)
                {
                    message.To.Add(str);
                }
            }
            message.Subject         = text.EmailSubject;
            message.SubjectEncoding = Encoding.UTF8;
            message.Body            = text.EmailBody;
            message.BodyEncoding    = Encoding.UTF8;
            message.IsBodyHtml      = true;
            message.Priority        = MailPriority.High;
            Guid guid = Guid.NewGuid();

            client.Send(message);
        }