Esempio n. 1
0
        public void Send(EmailMessage message, SmtpParameters sp)
        {
            EmailMessageCollection messages = new EmailMessageCollection();

            messages.Add(message);

            Send(messages, sp);
        }
Esempio n. 2
0
        public void Send(EmailMessage message, SmtpParameters sp, bool throwError = false)
        {
            EmailMessageCollection messages = new EmailMessageCollection();

            messages.Add(message);

            Send(messages, sp, throwError);
        }
        public void Send(EmailMessage message, SmtpParameters sp)
        {
            EmailMessageCollection messages = new EmailMessageCollection();

            messages.Add(message);

            Send(messages, sp);
        }
Esempio n. 4
0
        public SmtpParameters ToSmtpParameters()
        {
            ServerInfoConfigSettings.GetConfig().ServerInfos.ContainsKey(ServerInfoName).FalseThrow("生成Smtp信息时,不能找到'{0}'对应的ServerInfo信息",
                                                                                                    ServerInfoName);

            SmtpParameters result = new SmtpParameters();

            result.ServerInfo            = ServerInfoConfigSettings.GetConfig().ServerInfos[ServerInfoName].ToServerInfo();
            result.AfterSentOP           = this.AfterSentOP;
            result.UseDefaultCredentials = this.UseDefaultCredentials;
            result.DefaultSender         = EmailAddress.FromDescription(this.DefaultSender);

            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// 发送候选的邮件
        /// </summary>
        /// <param name="batchCount"></param>
        /// <param name="sp"></param>
        public void SendCandidateMessages(int batchCount, SmtpParameters sp)
        {
            sp.NullCheck("sp");

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                EmailMessageCollection messages = LoadCandidateMessages(batchCount);

                this.Send(messages, sp);

                this.DeleteEmailMessagesMainData(messages);

                scope.Complete();
            }
        }
Esempio n. 6
0
        public void Send(IEnumerable <EmailMessage> messages, SmtpParameters sp, bool throwError = false)
        {
            messages.NullCheck("messages");
            sp.NullCheck("sp");

            sp.CheckParameters();

            using (SmtpClient client = sp.ToSmtpClient())
            {
                foreach (EmailMessage message in messages)
                {
                    EmailMessage clonedMessage = message.Clone();

                    if (clonedMessage.From == null)
                    {
                        clonedMessage.From = sp.DefaultSender;
                    }

                    try
                    {
                        clonedMessage.Attachments.ForEach(ea => ea.PrepareContent());
                        client.Send(clonedMessage.ToMailMessage());
                        clonedMessage.Status = EmailMessageStatus.Sent;
                    }
                    catch (System.Exception ex)
                    {
                        if (throwError)
                        {
                            throw;
                        }

                        clonedMessage.Status     = EmailMessageStatus.Fail;
                        clonedMessage.StatusText = ex.ToString();
                    }

                    if (sp.AfterSentOP == EmailMessageAfterSentOP.MoveToSentTable ||
                        (sp.AfterSentOP == EmailMessageAfterSentOP.OnlyPersistErrorMessages && clonedMessage.Status == EmailMessageStatus.Fail))
                    {
                        InsertSentMessage(clonedMessage);
                    }
                }
            }
        }
        public void Send(IEnumerable<EmailMessage> messages, SmtpParameters sp)
        {
            messages.NullCheck("messages");
            sp.NullCheck("sp");

            sp.CheckParameters();

            using (SmtpClient client = sp.ToSmtpClient())
            {
                foreach (EmailMessage message in messages)
                {
                    EmailMessage clonedMessage = message.Clone();

                    if (clonedMessage.From == null)
                        clonedMessage.From = sp.DefaultSender;

                    try
                    {
                        clonedMessage.Attachments.ForEach(ea => ea.PrepareContent());
                        client.Send(clonedMessage.ToMailMessage());
                        clonedMessage.Status = EmailMessageStatus.Sent;
                    }
                    catch (System.Exception ex)
                    {
                        clonedMessage.Status = EmailMessageStatus.Fail;
                        clonedMessage.StatusText = ex.ToString();
                    }

                    if (sp.AfterSentOP == EmailMessageAfterSentOP.MoveToSentTable ||
                        (sp.AfterSentOP == EmailMessageAfterSentOP.OnlyPersistErrorMessages && clonedMessage.Status == EmailMessageStatus.Fail))
                    {
                        InsertSentMessage(clonedMessage);
                    }
                }
            }
        }
		public SmtpParameters ToSmtpParameters()
		{
			ServerInfoConfigSettings.GetConfig().ServerInfos.ContainsKey(ServerInfoName).FalseThrow("生成Smtp信息时,不能找到'{0}'对应的ServerInfo信息",
				ServerInfoName);

			SmtpParameters result = new SmtpParameters();

			result.ServerInfo = ServerInfoConfigSettings.GetConfig().ServerInfos[ServerInfoName].ToServerInfo();
			result.AfterSentOP = this.AfterSentOP;
			result.UseDefaultCredentials = this.UseDefaultCredentials;
			result.DefaultSender = EmailAddress.FromDescription(this.DefaultSender);

			return result;
		}
Esempio n. 9
0
        /// <summary>
        /// 发送候选的邮件
        /// </summary>
        /// <param name="batchCount"></param>
        public void SendCandidateMessages(int batchCount)
        {
            SmtpParameters sp = EmailMessageSettings.GetConfig().ToSmtpParameters();

            SendCandidateMessages(batchCount, sp);
        }
Esempio n. 10
0
		private SendMailParameters CollectInfo()
		{
			SendMailParameters result = new SendMailParameters();

			SmtpParameters sp = new SmtpParameters();

			LogOnIdentity identity = new LogOnIdentity(textBoxLogOnName.Text, textBoxPassword.Text);

			ServerInfo serverInfo = new ServerInfo(textBoxServer.Text, identity);

			int port = 0;

			if (int.TryParse(textBoxPort.Text, out port))
				serverInfo.Port = port;

			serverInfo.AuthenticateType = (AuthenticateType)Enum.Parse(typeof(AuthenticateType), (string)comboBoxAuthenticateType.SelectedValue);

			sp.ServerInfo = serverInfo;
			sp.UseDefaultCredentials = serverInfo.AuthenticateType == AuthenticateType.Anonymous;

			if (textBoxSignInAddress.Text.IsNotEmpty())
				sp.DefaultSender = EmailAddress.FromDescription(textBoxSignInAddress.Text);

			sp.AfterSentOP = EmailMessageAfterSentOP.NotPersisted;

			result.SmtpParams = sp;
			result.DefaultEmailSubject = textBoxMessage.Text;
			result.ToAddress = EmailAddress.FromDescription(textBoxDest.Text);

			return result;
		}
        /// <summary>
        /// 发送候选的邮件
        /// </summary>
        /// <param name="batchCount"></param>
        /// <param name="sp"></param>
        public void SendCandidateMessages(int batchCount, SmtpParameters sp)
        {
            sp.NullCheck("sp");

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                EmailMessageCollection messages = LoadCandidateMessages(batchCount);

                this.Send(messages, sp);

                this.DeleteEmailMessagesMainData(messages);

                scope.Complete();
            }
        }