コード例 #1
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;
     }
 }
コード例 #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
ファイル: ReceiveMail.cs プロジェクト: unicloud/AFRP
 public ReceiverMail(Guid Receiver)
 {
     _Pop3Client = new POP3_Client();
     _Account = MailAccountHelper.GetMailAccount(Receiver);
     _InvalidMails = new ManageMail();
        // _FE = new FleetEntities();
     _ReceiverObjects = new List<ReceiverObject>();
 }
コード例 #4
0
ファイル: SendContainer.cs プロジェクト: unicloud/AFRP
 public ISendMail GetSendClassBySender(BaseMailAccount Sender)
 {
     foreach (ISendMail ISM in _SendObjects)
     {
         if (ISM.CanSend(Sender))
         {
             return ISM;
         }
     }
     return null;
 }
コード例 #5
0
ファイル: SendMail.cs プロジェクト: unicloud/AFRP
 public BaseMailMessage GenMail(BaseMailAccount Sender, BaseMailAccount Receiver, object obj, string mailSubject, string attName)
 {
     // 生成邮件
     BaseMailMessage message = new BaseMailMessage();
     message.Sender = Sender.MailAddress;
     message.DisplayName = Sender.DisplayName;
     message.From = Sender.MailAddress;
     message.To = Receiver.MailAddress;
     message.Subject = mailSubject;
     message.Body = mailSubject + "\r\n" + "来自" + Sender.UserName;
     message.Priority = MailPriority.High;
     message.Attachments.Add(CreateMessageAttachment(obj, attName));
     return message;
 }
コード例 #6
0
ファイル: SendMail.cs プロジェクト: unicloud/AFRP
 /// <summary>
 /// 通过邮件发送数据文件的方法
 /// </summary>
 /// <param name="Sender">发送的账号</param>
 /// <param name="Receiver">接收的账号</param>
 /// <param name="obj">发送的对象</param>
 /// <param name="mailSubject">发送邮件的主题</param>
 /// <param name="attName">附件的名称</param>
 public int SendEntity(BaseMailAccount Sender, BaseMailAccount Receiver, object obj, string mailSubject, string attName)
 {
     try
     {
         //生成邮件
         BaseMailMessage message = this.GenMail(Sender, Receiver, obj, mailSubject, attName);
         //发送邮件
         return this.SendMessage(Sender, Receiver, message);
     }
     catch (Exception ex)
     {
         return -3;
     }
 }
コード例 #7
0
ファイル: LumiSoftSend.cs プロジェクト: unicloud/AFRP
 public int SendTest(BaseMailAccount Sender, BaseMailAccount Receiver)
 {
     Mail_Message msg = CreateTestMail(Sender, Receiver);
     MemoryStream m = MessageToStream(msg);
     try
     {
         SendMessage(Sender, Receiver, m);
         return 0;
     }
     catch (Exception ex)
     {
         this.EncodeErrorMessage(ex);
         return -1;
         throw ex;
     }
 }
コード例 #8
0
ファイル: SendMail.cs プロジェクト: unicloud/FRP
 public int SendNormalMail(BaseMailAccount sender, MailMessage message)
 {
     try
     {
         var sc = new SendContainer();
         ISendMail ISM = sc.GetSendClassBySender(sender);
         if (ISM != null)
         {
             return ISM.SendMail(sender, message);
         }
         return -1;
     }
     catch (Exception ex)
     {
         return -2;
     }
 }
コード例 #9
0
ファイル: NetSelfSend.cs プロジェクト: unicloud/FRP
 /// <summary>
 /// 发送邮件
 /// </summary>
 /// <param name="sender">发件账户</param>
 /// <param name="message"></param>
 public int SendMail(BaseMailAccount sender, MailMessage message)
 {
     try
     {
         //邮箱设置
         InitSmtpClient(sender);
         //发送邮件
         int intSend = SendMessage(message);
         //断开连接
         CloseConnection();
         return intSend;
     }
     catch (Exception ex)
     {
         this.EncodeErrorMessage(ex);
         return -3;
     }
 }
コード例 #10
0
ファイル: MailAccountHelper.cs プロジェクト: unicloud/AFRP
        private static BaseMailAccount SetDefaultProperty()
        {
            var account = new BaseMailAccount
                {
                    MailAddress = "",
                    DisplayName = "",
                    UserName = "",
                    Password = "",
                    ReceiveHost = "",
                    ReceivePort = 110,
                    ReceiveSsl = false,
                    SendHost = "",
                    SendPort = 25,
                    SendSsl = false,
                    SendStartTLS = false
                };

            return account;
        }
コード例 #11
0
ファイル: MailAccountHelper.cs プロジェクト: unicloud/FRP
        public static BaseMailAccount GetMailAccountFromAddr(string address, string displayName, string loginUser, string originPassword,
            string pop3Host,int receivePort,bool receiveSsl,string sendHost,int sendPort,bool sendSsl,bool startTls)
        {
            var account = new BaseMailAccount
                {
                    MailAddress = address,
                    DisplayName = displayName,
                    UserName = loginUser,
                    Password = originPassword,
                    ReceiveHost = pop3Host,
                    ReceivePort = receivePort,
                    ReceiveSsl = receiveSsl,
                    SendHost = sendHost,
                    SendPort = sendPort,
                    SendSsl = sendSsl,
                    SendStartTLS = startTls
                };

            return account;
        }
コード例 #12
0
ファイル: NetSelfSend.cs プロジェクト: unicloud/AFRP
        public int SendTest(BaseMailAccount Sender, BaseMailAccount Receiver)
        {
            try
            {
                //生成邮件
                MailMessage msg = CreateTestMail(Sender, Receiver);
                //邮箱设置
                InitSmtpClient(Sender);
                //发送邮件
                int intSend = SendMessage(msg);
                //断开连接
                CloseConnection();

                return intSend;
            }
            catch (Exception ex)
            {
                this.EncodeErrorMessage(ex);
                return -3;
            }
        }
コード例 #13
0
ファイル: Form1.cs プロジェクト: unicloud/AFRP
        private BaseMailAccount CreateSender()
        {
            BaseMailAccount _Sender = new BaseMailAccount();
            _Sender.DisplayName = tbMailAddress.Text;
            _Sender.MailAddress = tbMailAddress.Text;
            _Sender.UserName = tbUserName.Text;
            _Sender.Password = tbPassword.Text;

            _Sender.SendPort = int.Parse(tbSmtpPort.Text);
            _Sender.SendHost = this.tbSmtpName.Text;
            _Sender.SendSsl = this.cbSendSSl.Checked;

            return _Sender;
        }
コード例 #14
0
ファイル: Form1.cs プロジェクト: unicloud/AFRP
 private BaseMailAccount CreateReceiver()
 {
     BaseMailAccount _Receiver = new BaseMailAccount();
     _Receiver.MailAddress = tbReceiveAccount.Text;
     _Receiver.UserName = tbReceiveAccount.Text;
     return _Receiver;
 }
コード例 #15
0
ファイル: SendMail.cs プロジェクト: unicloud/FRP
 /// <summary>
 ///     测试邮件发送
 /// </summary>
 /// <param name="sender">发送的账号</param>
 /// <param name="receiver">接收的账号</param>
 public int SendTestMail(BaseMailAccount sender, string receiver)
 {
     try
     {
         var sc = new SendContainer();
         ISendMail ISM = sc.GetSendClassBySender(sender);
         if (ISM != null)
         {
             MailMessage msg=new MailMessage();
             msg.From = (new MailAddress(sender.MailAddress));
             msg.To.Add(new MailAddress(receiver));
             return ISM.SendTest(sender,msg);
         }
         return -1;
     }
     catch (Exception ex)
     {
         return -2;
     }
 }
コード例 #16
0
ファイル: SendMail.cs プロジェクト: unicloud/AFRP
 /// <summary>
 /// 测试邮件发送
 /// </summary>
 /// <param name="Sender">发送的账号</param>
 /// <param name="Receiver">接收的账号</param>
 public int SendTestMail(BaseMailAccount Sender, BaseMailAccount Receiver)
 {
     try
     {
         SendContainer sc = new SendContainer();
         ISendMail ISM = sc.GetSendClassBySender(Sender);
         if (ISM != null)
         {
             return ISM.SendTest(Sender, Receiver);
         }
         return -1;
     }
     catch (Exception ex)
     {
         return -2;
     }
 }
コード例 #17
0
ファイル: SendMail.cs プロジェクト: unicloud/AFRP
 private int SendMessage(BaseMailAccount Sender, BaseMailAccount Receiver, BaseMailMessage message)
 {
     try
     {
         SendContainer sc = new SendContainer();
         ISendMail ISM = sc.GetSendClassBySender(Sender);
         if(ISM != null)
         {
            return ISM.SendMail(Sender, Receiver, message);
         }
         return -1;
     }
     catch (Exception ex)
     {
         return -2;
     }
 }
コード例 #18
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;
            }
        }
コード例 #19
0
ファイル: LumiSoftSend.cs プロジェクト: unicloud/AFRP
        private Mail_Message CreateTestMail(BaseMailAccount Sender, BaseMailAccount Receiver)
        {
            Mail_Message msg = new Mail_Message();
            msg.MimeVersion = "1.0";
            msg.MessageID = MIME_Utils.CreateMessageID();
            msg.Date = DateTime.Now;
            msg.From = new Mail_t_MailboxList();
            msg.From.Add(new Mail_t_Mailbox(Sender.DisplayName, Sender.MailAddress));
            msg.To = new Mail_t_AddressList();
            msg.To.Add(new Mail_t_Mailbox(Receiver.MailAddress, Receiver.MailAddress));
            msg.Subject = "Test Send Mail";
            //设置回执通知
            //string notifyEmail = SystemConfig.Default.DispositionNotificationTo;
            //if (!string.IsNullOrEmpty(notifyEmail) && ValidateUtil.IsEmail(notifyEmail))
            //{
            //    msg.DispositionNotificationTo = new Mail_t_Mailbox(notifyEmail, notifyEmail);
            //}

            #region MyRegion

            string BodyText = "这是一份测试邮件,来自<font color=red><b>厦门至正测试程序</b></font>";
            CreateBodyPart(msg, BodyText);

            //测试邮件不发送附件

            #endregion

            return msg;
        }
コード例 #20
0
ファイル: NetSelfSend.cs プロジェクト: unicloud/AFRP
        private MailMessage CreateTestMail(BaseMailAccount Sender, BaseMailAccount Receiver)
        {
            MailMessage msg = new MailMessage(Sender.MailAddress, Receiver.MailAddress);
            msg.Sender = new MailAddress(Sender.MailAddress, Sender.DisplayName);
            msg.Subject = "Test Send Mail By Net.Mail";
            msg.Body = "这是一份测试邮件,来自厦门至正测试程序";
            msg.Priority = MailPriority.High;

            //测试邮件不发送附件

            return msg;
        }
コード例 #21
0
ファイル: NetSelfSend.cs プロジェクト: unicloud/AFRP
 private void InitSmtpClient(BaseMailAccount Sender)
 {
     // 指定 smtp 服务器地址
     _Client.Host = Sender.SendHost;
     // 指定 smtp 服务器的端口,默认是25,如果采用默认端口,可省去
     _Client.Port = Sender.SendPort;
     // 将smtp的出站方式设为 Network
     _Client.DeliveryMethod = SmtpDeliveryMethod.Network;
     // SMTP服务器需要身份认证
     _Client.UseDefaultCredentials = true;
     // smtp服务器是否启用SSL加密
     _Client.EnableSsl = false;
     //设置发信凭据
     _Client.Credentials = new NetworkCredential(Sender.UserName, Sender.Password);
 }
コード例 #22
0
ファイル: MailAccountHelper.cs プロジェクト: unicloud/AFRP
        private static BaseMailAccount SetPropertyFromAddr(MailAddress addr)
        {
            var account = new BaseMailAccount
                {
                    MailAddress = addr.Address,
                    DisplayName = addr.DisplayName,
                    UserName = addr.LoginUser,
                    Password = addr.OriginPassword,
                    ReceiveHost = addr.Pop3Host,
                    ReceivePort = addr.ReceivePort,
                    ReceiveSsl = addr.ReceiveSSL,
                    SendHost = addr.SmtpHost,
                    SendPort = addr.SendPort,
                    SendSsl = addr.SendSSL,
                    SendStartTLS = addr.StartTLS
                };

            return account;
        }
コード例 #23
0
ファイル: NetSelfSend.cs プロジェクト: unicloud/AFRP
 public bool CanSend(BaseMailAccount Sender)
 {
     return Sender.SendSsl == false;
 }
コード例 #24
0
ファイル: ReceiveMail.cs プロジェクト: unicloud/FRP
 public ReceiverMail(BaseMailAccount receiver)
 {
     _pop3Client = new POP3_Client();
     _receiveAccount = receiver;//需要提前设置好接收账号用户密码及接收服务器,接收端口,是否ssl
     _invalidMails = new ManageMail();
 }
コード例 #25
0
ファイル: LumiSoftSend.cs プロジェクト: unicloud/FRP
 public bool CanSend(BaseMailAccount Sender)
 {
     return true;
 }