コード例 #1
0
        public async Task <dynamic> PrepareEmailNotification(string Type)
        {
            EmailViewModel                  emailViewModel = new EmailViewModel();
            EmailAttributesViewModel        eavm           = new EmailAttributesViewModel();
            List <EmailAttributesViewModel> eavms          = new List <EmailAttributesViewModel>();

            eavm.Name    = "Prakash Anban";
            eavm.EmailId = "*****@*****.**";
            eavms.Add(eavm);
            emailViewModel.ToEmailList      = eavms;
            emailViewModel.Subject          = "JobId - 1212, Plant XYZ Assinged to Review";
            emailViewModel.Body             = "Review Job - 1212";
            emailViewModel.IsCalendarInvite = false;

            return(await emailService.SendInvite(emailViewModel));
        }
コード例 #2
0
        public async Task <dynamic> PrepareUserEmailNotification(string UserName, string UserEmail, string ActivationURL)
        {
            EmailViewModel emailViewModel         = new EmailViewModel();
            List <EmailAttributesViewModel> eavms = new List <EmailAttributesViewModel>();
            EmailAttributesViewModel        eavm  = new EmailAttributesViewModel
            {
                Name    = UserName,
                EmailId = UserEmail
            };

            eavms.Add(eavm);
            emailViewModel.ToEmailList = eavms;
            emailViewModel.Subject     = "Account Activation";
            Cmssetup cmssetup = await cmsRepo.GetContentByTypeCode("O_UA");

            string EmailBody = cmssetup.TypeText.Replace("$@USER_NAME@$", UserName).Replace("$@USER_EMAIL@$", UserEmail).Replace("$@USER_MAIL_ACTIVATION_URL@$", ActivationURL);

            emailViewModel.Body = EmailBody;

            return(await emailService.SendInvite(emailViewModel));;
        }
コード例 #3
0
        public async Task <dynamic> PrepareUserPasswordNotification(string UserName, string UserEmail, string Password, string BaseUrl)
        {
            EmailViewModel emailViewModel         = new EmailViewModel();
            List <EmailAttributesViewModel> eavms = new List <EmailAttributesViewModel>();
            EmailAttributesViewModel        eavm  = new EmailAttributesViewModel
            {
                Name    = UserName,
                EmailId = UserEmail
            };

            eavms.Add(eavm);
            emailViewModel.ToEmailList = eavms;
            emailViewModel.Subject     = "Account Password";
            Cmssetup cmssetup = await cmsRepo.GetContentByTypeCode("O_UPN");

            string EmailBody = cmssetup.TypeText.Replace("$@USER_NAME@$", UserName).Replace("$@USER_EMAIL@$", UserEmail).Replace("$@USER_PASSWORD@$", Password).Replace("$@SIGN_IN_URL@$", BaseUrl);

            emailViewModel.Body = EmailBody;

            return(await emailService.SendInvite(emailViewModel));;
        }
コード例 #4
0
        public async Task <dynamic> SendInvite(EmailViewModel emailViewModel)
        {
            ApplicationConfigurationViewModel appConfig = null;
            string SmtpUrl       = null;
            string SmtpUN        = null;
            string SmtpPwd       = null;
            string SenderEmailId = null;
            int    Port          = 0;
            bool   EnableSsl     = false;

            try
            {
                appConfig = await appConfigRepo.GetAppConfigByName("O_SMTP_URL", "Y");

                SmtpUrl   = appConfig.AppConfigValue;
                appConfig = await appConfigRepo.GetAppConfigByName("O_SMTP_UN", "Y");

                SmtpUN    = appConfig.AppConfigValue;
                appConfig = await appConfigRepo.GetAppConfigByName("O_SMTP_PWD", "Y");

                SmtpPwd   = CustomUtils.DecodeFromBase64(appConfig.AppConfigValue);
                appConfig = await appConfigRepo.GetAppConfigByName("O_SMTP_PORT", "Y");

                Port      = Int32.Parse(appConfig.AppConfigValue);
                appConfig = await appConfigRepo.GetAppConfigByName("O_SENDER_EMAIL", "Y");

                SenderEmailId = appConfig.AppConfigValue;
                appConfig     = await appConfigRepo.GetAppConfigByName("O_SMTP_ENABLE_SSL", "Y");

                EnableSsl = bool.Parse(appConfig.AppConfigValue);

                // Create SMTP Client.
                SmtpClient        sc = new SmtpClient(SmtpUrl);
                NetworkCredential nc = new NetworkCredential(SmtpUN, SmtpPwd);
                sc.Port        = Port;
                sc.EnableSsl   = EnableSsl;
                sc.Credentials = nc;

                // Setup e-mail message
                System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();

                if (emailViewModel.FromEmail != null && emailViewModel.FromEmail.EmailId != null)
                {
                    msg.From = new MailAddress(emailViewModel.FromEmail.EmailId);
                }
                else
                {
                    EmailAttributesViewModel emailAttr = new EmailAttributesViewModel();
                    emailAttr.EmailId        = SenderEmailId;
                    emailAttr.Name           = SenderEmailId;
                    emailViewModel.FromEmail = emailAttr;
                    msg.From = new MailAddress(SenderEmailId);
                }

                AddToEmails(msg, emailViewModel.ToEmailList);
                ApplicationConfigurationViewModel sub = await appConfigRepo.GetAppConfigByName("O_APP_ENV", "Y");

                if (sub != null && sub.AppConfigValue != null && sub.AppConfigValue != "")
                {
                    emailViewModel.Subject = sub.AppConfigValue + " " + emailViewModel.Subject;
                    msg.Subject            = emailViewModel.Subject;
                }
                else
                {
                    msg.Subject = emailViewModel.Subject;
                }

                msg.Body       = emailViewModel.Body;
                msg.IsBodyHtml = true;

                if (emailViewModel.Attachments != null && emailViewModel.Attachments.Count > 0)
                {
                    // Need to write code for Attachments.
                }

                // The below method is used to send an Calendar Invite.
                if (emailViewModel.IsCalendarInvite)
                {
                    StringBuilder str = new StringBuilder();
                    str.AppendLine("BEGIN:VCALENDAR");
                    str.AppendLine("PRODID:-//" + emailViewModel.FromEmail.EmailId);
                    str.AppendLine("VERSION:2.0");
                    str.AppendLine("X-WR-TIMEZONE:Asia/Kolkata");
                    str.AppendLine("CALSCALE:GREGORIAN");
                    str.AppendLine("METHOD:REQUEST");
                    str.AppendLine("BEGIN:VEVENT");
                    str.AppendLine(string.Format("SUMMARY:{0}", emailViewModel.Subject));
                    str.AppendLine(string.Format("DESCRIPTION:{0}", emailViewModel.Body));
                    //str.AppendLine("BEGIN:VTIMEZONE");
                    str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", emailViewModel.StartDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z")));
                    str.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", new DateTime().ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z")));
                    str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", emailViewModel.EndDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z")));
                    str.AppendLine("LOCATION:" + emailViewModel.Location);
                    //str.AppendLine("END:VTIMEZONE");
                    str.AppendLine("CLASS:PUBLIC");
                    str.AppendLine("IMPORTANT:0");
                    str.AppendLine("STATUS: CONFIRMED");
                    str.AppendLine("COMMENT:");
                    str.AppendLine(string.Format("UID:{0}", Guid.NewGuid()));
                    str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", emailViewModel.Body));
                    str.AppendLine(string.Format("ORGANIZER;CN=\"{0}\":MAILTO:{0}", emailViewModel.FromEmail.EmailId));

                    foreach (MailAddress emto in msg.To)
                    {
                        str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;RSVP=TRUE;PARTSTAT=NEEDS-ACTION:mailto:{1}", emto.DisplayName, emto.Address));
                    }
                    //str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", emto.DisplayName, emto.Address));
                    //str.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", msg.To[0].DisplayName, msg.To[0].Address));
                    str.AppendLine("BEGIN:VALARM");
                    str.AppendLine("TRIGGER:-PT15M");
                    //str.AppendLine("ACTION:DISPLAY");
                    str.AppendLine("ACTION:EMAIL");
                    str.AppendLine("DESCRIPTION:Reminder");
                    str.AppendLine("END:VALARM");
                    str.AppendLine("END:VEVENT");
                    str.AppendLine("END:VCALENDAR");
                    System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
                    ct.Parameters.Add("method", "REQUEST");
                    AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), ct);
                    msg.AlternateViews.Add(avCal);
                }

                try
                {
                    sc.Send(msg);
                    return("Success");
                }
                catch (Exception ex)
                {
                    return("Fail Reason +++++++++ " + ex);
                }
            }
            catch (Exception e)
            {
                return("" + e);
            }
            return(string.Empty);
        }