SendMailAsync() public method

Run mail sending operation on a separate thread and asynchronously Operation does not return any information about completion.
public SendMailAsync ( ) : void
return void
Example #1
0
        /// <summary>
        /// Sends an Admin email with the Admin email name and email address from Web Store Config
        /// </summary>
        /// <param name="Subject"></param>
        /// <param name="Message"></param>
        /// <param name="Recipient"></param>
        /// <returns></returns>
        public static bool SendAdminEmail(string Subject, string Message, string ccList, string emailAddress = null)
        {
            if (string.IsNullOrEmpty(emailAddress))
                emailAddress = App.Configuration.AdminEmailAddress;

            try
            {
                SmtpClientNative Email = new SmtpClientNative();
                Email.MailServer = App.Configuration.MailServer;
                Email.Recipient = emailAddress;

                Email.SenderEmail = App.Configuration.AdminEmailAddress;
                Email.SenderName = App.Configuration.AdminEmailName;
                Email.ContentType = "text/plain";


                Email.Subject = Subject;
                Email.Message = Message;

                // *** Capture errors so we can log them
                Email.SendError += OnSmtpError;

                Email.SendMailAsync();
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }
Example #2
0
        /// <summary>
        /// Sends email using the WebStoreConfig Email Configuration defaults.
        /// 
        /// <seealso>Class WebUtils</seealso>
        /// </summary>
        /// <param name="Subject">
        /// The subject of the message.
        /// </param>
        /// <param name="Message">
        /// The body of the message.
        /// </param>
        /// <param name="Recipient">
        /// The recipient as an email address.
        /// </param>
        /// <param name="SendName">
        /// Name descriptive of the sender.
        /// </param>
        /// <param name="SendEmail">
        /// The email address of the sender.
        /// </param>
        /// <param name="NoAsync">
        /// Whether this message is send asynchronously or not.
        /// </param>
        /// <param name="Boolean SendAsText">
        /// Determines whether the message is sent as Text or HTML.
        /// </param>
        /// <returns>Boolean</returns>
        public static bool SendEmail(string Subject, string Message, string Recipient, string SendName,
                                     string SendEmail, bool NoAsync, bool SendAsText, delSmtpNativeEvent OnErrorHandler)
        {
            try
            {
                SmtpClientNative Email = new SmtpClientNative();
                Email.MailServer = App.Configuration.MailServer;
                if (!string.IsNullOrEmpty(App.Configuration.MailServerUsername))
                {
                    Email.Username = App.Configuration.MailServerUsername;
                    Email.Password = App.Configuration.MailServerPassword;
                }
                Email.Recipient = Recipient;

                if (SendAsText)
                    Email.ContentType = "text/plain";
                else
                {
                    Email.ContentType = "text/html; charset=utf-8";
                    Email.Encoding = Encoding.UTF8;
                }


                if (SendName == null || SendName == "")
                {
                    Email.SenderEmail = App.Configuration.SenderEmailAddress;
                    Email.SenderName = App.Configuration.SenderEmailName;
                }
                else
                {
                    Email.SenderEmail = SendEmail;
                    Email.SenderName = SendName;
                }

                Email.Subject = Subject;
                Email.Message = Message;

                // *** Capture any error messages and log them
                if (OnErrorHandler == null)
                    Email.SendError += OnSmtpError;
                else
                    Email.SendError += OnErrorHandler;

                if (NoAsync)
                    return Email.SendMail();
                else
                    Email.SendMailAsync();
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }