示例#1
0
        public void DispatchEmailMessage(EmailMessage email)
        {
            try
            {
                if (string.IsNullOrEmpty(email.ToEmailAddress))
                {
                    email.ToEmailAddress = ConfigItems.SystemEmailAddress;
                    email.ToName = "AirtimeBilling No Address";
                }

                using (var outgoing = email.GetMessage()) {
                    var mailClient = new SmtpClient();

                    mailClient.Send(outgoing);

                    var emailLogMsg = string.Format("Sent email SMTP Server: {0}, Mail From: {1}, Mail To: {2}", mailClient.Host,
                                                outgoing.From.Address, outgoing.To[0].Address);
                    LoggingUtility.LogDebug("DispatchEmailMessage", "EmailService", emailLogMsg);
                }
            }
            catch (Exception ex)
            {
                // Do not send Error email.
                LoggingUtility.LogException(ex, false);
            }
        }
示例#2
0
        public static void SendEmailWithAttachments(string toAddress, string toName, string subject, IEmailFormat message, bool highPriority, IList<string> attachmentFilenames)
        {
            var msg = new EmailMessage
            {
                ToEmailAddress = toAddress,
                ToName = toName,
                Subject = subject,
                Body = message.GetHtml(),
                IsBodyHtml = true,
                IsHighPriority = highPriority,
                FilesToAttach = attachmentFilenames ?? new List<string>()
            };

            EmailMessageAgent agent = null;
            try
            {
                agent = new EmailMessageAgent();
                agent.DispatchEmailMessage(msg);
            }
            finally
            {
                if (agent != null)
                    agent.Close();
            }
        }
示例#3
0
        public static void SendEmail(string toAddress, string toName, string subject, IEmailFormat message, bool highPriority)
        {
            var msg = new EmailMessage
                          {
                              ToEmailAddress = toAddress,
                              ToName = toName,
                              Subject = subject,
                              Body = message.GetHtml(),
                              IsBodyHtml = true,
                              IsHighPriority = highPriority,
                            };

            EmailMessageAgent agent = null;
            try
            {
                agent = new EmailMessageAgent();
                agent.DispatchEmailMessage(msg);
            }
            finally
            {
                if (agent != null)
                    agent.Close();
            }
        }