示例#1
0
        public static async Task SendNotificationEmailAsync(NotifcationMessage message)
        {
            //Steps for composing the CustomSource
            //message.SourceName =  userHelper.GetUserNameFromId(message.RecipientId);
            //message.CustomSource = message.SourceName + WebConfigurationManager.AppSettings["emailsource"];

            //Get data from our private.Config for usage within the SMTP object
            var gmailUsername = WebConfigurationManager.AppSettings["username"];
            var gmailPassword = WebConfigurationManager.AppSettings["password"];
            var gmailHost     = WebConfigurationManager.AppSettings["host"];
            var gmailPort     = Convert.ToInt32(WebConfigurationManager.AppSettings["port"]);

            using (var smtp = new SmtpClient()
            {
                Host = gmailHost,
                Port = gmailPort,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(gmailUsername, gmailPassword)
            })

                try
                {
                    await smtp.SendMailAsync("EMS<*****@*****.**>", message.RecipientEmail, "A message from EMS", message.Body);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    await Task.FromResult(0);
                }
        }
示例#2
0
        public async Task NotificationEmailCreator(TicketNotification notification, string oldUserId, string newUserId)
        {
            UserHelper userHelper   = new UserHelper();
            var        oldUserEmail = userHelper.GetUserEmailFromId(oldUserId);
            var        newUserEmail = userHelper.GetUserEmailFromId(newUserId);

            var notificationMessage = new NotifcationMessage();

            if (!string.IsNullOrEmpty(oldUserId))
            {
                //Send email to old user
                notificationMessage.RecipientEmail = oldUserEmail;
                notificationMessage.Body           = notification.NotifyReason;
                await EmailHelper.SendNotificationEmailAsync(notificationMessage);
            }

            if (!string.IsNullOrEmpty(newUserId))
            {
                //Send email to old user
                notificationMessage.RecipientEmail = newUserEmail;
                notificationMessage.Body           = notification.NotifyReason;
                await EmailHelper.SendNotificationEmailAsync(notificationMessage);
            }
        }