示例#1
0
        public async Task SendAsync(EmailIdentityMessage message)
        {
            var email = new MailMessage();

            email.From = new MailAddress(message.Destination.Trim());

            //split the value semi-colon separated value
            string[] recipients = message.To.Split(';').Select(sValue => sValue.Trim()).ToArray();

            //loop and add a new instance of MailAddress
            for (int i = 0; i < recipients.Length; i++)
            {
                if (!string.IsNullOrWhiteSpace(recipients[i]))
                {
                    email.To.Add(new MailAddress(recipients[i]));
                }
            }

            email.Subject    = message.Subject;
            email.Body       = message.Body;
            email.IsBodyHtml = true;

            var host = ConfigurationManager.AppSettings["SmtpHost"];
            var port = Convert.ToInt32(ConfigurationManager.AppSettings["SmtpPort"]);

            using (var client = new SmtpClient(host, port))
            {
                client.Credentials = new System.Net.NetworkCredential(message.Destination.Trim(), message.Credential.Trim());

                await client.SendMailAsync(email);
            }
        }
示例#2
0
        public async Task CustomSendEmailAsync(string userId, string subject, string body, string recipient)
        {
            if (CustomEmailService == null)
            {
                throw new NotImplementedException("MessageService has not been implemented.");
            }

            var identityMessage = new EmailIdentityMessage();
            var user            = await FindByIdAsync(userId);

            identityMessage.Destination = user.Email; //from
            identityMessage.Subject     = subject;
            identityMessage.Body        = body;
            identityMessage.To          = recipient;
            identityMessage.Credential  = user.EmailPass;

            await CustomEmailService.SendAsync(identityMessage);
        }