Ejemplo n.º 1
0
        /// <summary>
        /// Sends mail async.
        /// </summary>
        /// <param name="fromAddress">From email address.</param>
        /// <param name="subject">Subject.</param>
        /// <param name="message">Message.</param>
        /// <param name="bodyHtml">Sets message is HTML.</param>
        /// <param name="userToken">User token for async.</param>
        /// <param name="sendToAddress">Send to email address.</param>
        public void SendMailAsync(EmailAddress fromAddress, string subject, string message, bool bodyHtml, object userToken, EmailAddress sendToAddress)
        {
            Encapsulation.TryValidateParam <ArgumentNullException>(fromAddress.IsNotNull(), nameof(fromAddress));
            Encapsulation.TryValidateParam(subject, nameof(subject));
            Encapsulation.TryValidateParam(message, nameof(message));
            Encapsulation.TryValidateParam <ArgumentNullException>(sendToAddress.IsNotNull(), nameof(sendToAddress));

            // 'Set default types, just in case.
            sendToAddress.EmailAddressType = EmailAddressType.SendTo;

            this.SendMailAsync(fromAddress, subject, message, bodyHtml, userToken, sendToAddress);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends email with the users default email application.
        /// </summary>
        /// <param name="subject">Subject of the email.</param>
        /// <param name="message">Email message.</param>
        /// <param name="sendToAddress">Email address to send to.</param>
        /// <exception cref="ArgumentException">sendToAddress.</exception>
        /// <exception cref="System.ArgumentException">sendToAddress.</exception>
        public static void SendMailWithDefaultProgram(string subject, string message, EmailAddress sendToAddress)
        {
            Encapsulation.TryValidateParam(subject, nameof(subject));
            Encapsulation.TryValidateParam(message, nameof(message));
            Encapsulation.TryValidateParam <ArgumentInvalidException>(sendToAddress.IsAddressValid() == false);

            using (var mailProcess = new Process())
            {
                var processInfo = new ProcessStartInfo()
                {
                    FileName        = string.Format(CultureInfo.InvariantCulture, "mailto:{0}?subject={1}&body={2}", sendToAddress.Address, subject, message),
                    UseShellExecute = true,
                    WindowStyle     = ProcessWindowStyle.Normal,
                };

                mailProcess.StartInfo = processInfo;
                Process.Start(processInfo);
            }
        }