예제 #1
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 = AppSecurity.Configuration.MailServer;
                if (!string.IsNullOrEmpty(AppSecurity.Configuration.MailServerUsername))
                {
                    Email.Username = AppSecurity.Configuration.MailServerUsername;
                    Email.Password = AppSecurity.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 = AppSecurity.Configuration.SenderEmailAddress;
                    Email.SenderName  = AppSecurity.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);
        }
예제 #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;
        }