コード例 #1
0
ファイル: SendMailLumiSoft.cs プロジェクト: unicloud/AFRP
        //public MailMessage GenMail(string mailSubject)
        //{
        //    // 生成邮件
        //    MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**");
        //    message.Sender = new MailAddress("*****@*****.**");
        //    message.Subject = mailSubject;
        //    message.Body = "*****@*****.**" + " Send " + mailSubject;
        //    message.Priority = MailPriority.High;
        //    return message;
        //}
        public int SendMail(MailAccount Sender, MailAccount Receiver, string mailSubject)
        {
            Mail_Message msg = Create_PlainText_Html_Attachment_Image(Receiver.UserName, Sender.MailAddress, Sender.UserName);
            MemoryStream m = new MemoryStream();
            MIME_Encoding_EncodedWord ew = new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.B, Encoding.UTF8);
            msg.ToStream(m, ew, Encoding.UTF8, false);
            m.Position = 0;

            LumiSoft.Net.SMTP.Client.SMTP_Client smtpClient;

            smtpClient = new LumiSoft.Net.SMTP.Client.SMTP_Client();

            try
            {
                smtpClient.Connect(Sender.SmtpHost, Sender.SendPort, Sender.SendSsl);
                try
                {
                    smtpClient.EhloHelo(Sender.SmtpHost);
                    smtpClient.Authenticate(Sender.UserName, Sender.Password);
                    smtpClient.MailFrom(Sender.UserName, -1);
                    smtpClient.RcptTo(Receiver.UserName);
                    smtpClient.SendMessage(m);
                }
                finally
                {
                    smtpClient.Disconnect();
                }
            }
            finally
            {
                smtpClient = null;
            }
            return 0;
        }
コード例 #2
0
ファイル: LumiSoftSend.cs プロジェクト: unicloud/FRP
        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="sender">发件账户</param>
        /// <param name="message"></param>
        public string SendMail(BaseMailAccount sender, MailMessage message)
        {
            LumiSoft.Net.SMTP.Client.SMTP_Client smtpClient;
            smtpClient = new LumiSoft.Net.SMTP.Client.SMTP_Client();

            try
            {
                smtpClient.Connect(sender.SendHost, sender.SendPort, sender.SendSsl);
                Mail_Message msg = TransferMessage(message);
                MemoryStream m = MessageToStream(msg);
                try
                {
                    smtpClient.EhloHelo(sender.SendHost);
                    smtpClient.Auth(new LumiSoft.Net.AUTH.AUTH_SASL_Client_Login(sender.UserName,sender.Password));
                    //smtpClient.Authenticate(Sender.UserName, Sender.Password);
                    smtpClient.MailFrom(sender.UserName, -1);
                    message.To.ToList().ForEach(p => smtpClient.RcptTo(p.Address));
                    smtpClient.SendMessage(m);
                }
                finally
                {
                    smtpClient.Disconnect();
                }
                return "邮件已发送,请查收!";
            }
            catch (Exception ex)
            {
                return "邮件发送失败,原因:" + ex.Message;
            }
        }
コード例 #3
0
ファイル: LumiSoftSend.cs プロジェクト: unicloud/FRP
 public int SendTest(BaseMailAccount sender, MailMessage message)
 {
     LumiSoft.Net.SMTP.Client.SMTP_Client smtpClient;
     smtpClient = new LumiSoft.Net.SMTP.Client.SMTP_Client();
     Mail_Message msg = CreateTestMail(message);
     MemoryStream m = MessageToStream(msg);
     try
     {
         smtpClient.Connect(sender.SendHost, sender.SendPort, sender.SendSsl);
         try
         {
             smtpClient.EhloHelo(sender.SendHost);
             smtpClient.Auth(new LumiSoft.Net.AUTH.AUTH_SASL_Client_Login(sender.UserName, sender.Password));
             //smtpClient.Authenticate(Sender.UserName, Sender.Password);
             smtpClient.MailFrom(sender.UserName, -1);
             message.To.ToList().ForEach(p => smtpClient.RcptTo(p.Address));
             smtpClient.SendMessage(m);
         }
         finally
         {
             smtpClient.Disconnect();
         }
         return 0;
     }
     catch (Exception ex)
     {
         this.EncodeErrorMessage(ex);
         return -1;
         throw ex;
     }
 }
コード例 #4
0
ファイル: LumiSoftSend.cs プロジェクト: unicloud/AFRP
        private static void SendMessage(BaseMailAccount Sender, BaseMailAccount Receiver, MemoryStream m)
        {
            LumiSoft.Net.SMTP.Client.SMTP_Client smtpClient;

            smtpClient = new LumiSoft.Net.SMTP.Client.SMTP_Client();

            try
            {
                smtpClient.Connect(Sender.SendHost, Sender.SendPort, Sender.SendSsl);
                try
                {
                    smtpClient.EhloHelo(Sender.SendHost);
                    smtpClient.Auth(new LumiSoft.Net.AUTH.AUTH_SASL_Client_Login(Sender.UserName, Sender.Password));
                   // smtpClient.Authenticate(Sender.UserName, Sender.Password);
                    smtpClient.MailFrom(Sender.UserName, -1);
                    smtpClient.RcptTo(Receiver.UserName);
                    smtpClient.SendMessage(m);
                }
                finally
                {
                    smtpClient.Disconnect();
                }
            }
            finally
            {
                smtpClient = null;
            }
        }