Пример #1
0
        public void SendEmail(IdentityMessageModel messageModel)
        {
            using (var client = new SmtpClient())
            {
                try
                {
                    var mimeMessage = CreateMimeMessage(messageModel);

                    client.Connect(_emailSettings.MailServer, _emailSettings.Port, true);
                    client.AuthenticationMechanisms.Remove("XOAUTH2");
                    client.Authenticate(_emailSettings.Username, _emailSettings.Password);
                    client.Send(mimeMessage);
                }
                catch
                {
                    Log.Current.Error("Error sending email");
                    throw;
                }
                finally
                {
                    client.Disconnect(true);
                    client.Dispose();
                }
            }
        }
Пример #2
0
        private MimeMessage CreateMimeMessage(IdentityMessageModel messageModel)
        {
            var mimeMessage = new MimeMessage();

            mimeMessage.From.Add(new MailboxAddress(_emailSettings.SenderName, _emailSettings.Username));
            mimeMessage.To.AddRange(messageModel.Destinations.Select(x => new MailboxAddress(_emailSettings.SenderName, x)));
            mimeMessage.Subject = messageModel.Subject;
            mimeMessage.Body    = new TextPart(MimeKit.Text.TextFormat.Html)
            {
                Text = messageModel.Content
            };

            return(mimeMessage);
        }
Пример #3
0
        public void SendSms(IdentityMessageModel messageModel)
        {
            try
            {
                TwilioClient.Init(_accountSid, _authToken);

                var message = MessageResource.Create(body: messageModel.Content,
                                                     from: new Twilio.Types.PhoneNumber(_twilioPhone),
                                                     to: new Twilio.Types.PhoneNumber(messageModel.Destinations?[0])
                                                     );
            }
            catch
            {
                Log.Current.Error("Error sending sms");
                throw;
            }
        }