示例#1
0
        public async Task LogQuotaExceedEmailToDisk(EmailTypes emailType, string emailTo, string subject, string body, int userId)
        {
            string solutionFolder          = Directory.GetParent(_appPath).Parent?.FullName;
            string logsFolder              = $@"{solutionFolder}\Logs";
            string rejectedEmailLogsFolder = $@"{logsFolder}\EmailsOutRejected";

            Directory.CreateDirectory(rejectedEmailLogsFolder);

            string emailDate = DateTime.Now.ToString("yyyy-MM-ddTHH-mm-ss");
            string fileName  = $"{emailType}-{userId}-{emailDate}.json";
            string filePath  = $@"{rejectedEmailLogsFolder}\{fileName}";
            string fileText  = JsonConvert.SerializeObject(new { Type    = emailType.ToString(),
                                                                 To      = emailTo,
                                                                 Subject = subject,
                                                                 Text    = body }, Formatting.Indented);

            await Task.Run(() =>
            {
                if (File.Exists(filePath))
                {
                    filePath = filePath.Replace(".json", $"-({DateTime.Now.Ticks}).json");
                }
                File.WriteAllText(filePath, fileText);
            });
        }
示例#2
0
 public MailMessage(string to, string name, string message, EmailTypes type)
 {
     To        = to;
     Name      = name;
     Message   = message;
     EmailType = type;
 }
示例#3
0
        public void Run(EmailTypes emailTypeToSend)
        {
            var emailType = EmailTypesFactory.Create()[emailTypeToSend];

            string templatePath = Path.Combine(configuration.Templates_Directory, emailType.EmailTemplateFilename);
            string templateHtml = File.ReadAllText(templatePath);

            using (var connection = new SqlConnection(configuration.Database_ConnectionString))
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = emailType.Query;

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string speakerName = reader.GetString(reader.GetOrdinal("Name"));
                            string speakerEmailAddress = reader.GetString(reader.GetOrdinal("EmailAddress"));
                            string sessionTitle = reader.GetString(reader.GetOrdinal("Title"));

                            string emailContents = PrepeareEmail(templateHtml, speakerName, sessionTitle);
                            emailSender.SendEmail(speakerEmailAddress, emailContents);
                        }
                    }
                }
            }
        }
示例#4
0
        public void Run(EmailTypes emailTypeToSend)
        {
            var emailType = EmailTypesFactory.Create()[emailTypeToSend];

            string templatePath = Path.Combine(configuration.Templates_Directory, emailType.EmailTemplateFilename);
            string templateHtml = File.ReadAllText(templatePath);

            using (var connection = new SqlConnection(configuration.Database_ConnectionString))
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = emailType.Query;

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string speakerName         = reader.GetString(reader.GetOrdinal("Name"));
                            string speakerEmailAddress = reader.GetString(reader.GetOrdinal("EmailAddress"));
                            string sessionTitle        = reader.GetString(reader.GetOrdinal("Title"));

                            string emailContents = PrepeareEmail(emailTypeToSend, templateHtml, speakerName, sessionTitle);
                            emailSender.SendEmail(speakerEmailAddress, emailContents);
                        }
                    }
                }
            }
        }
        private async Task SendMail(EmailTypes emailType, SendGridMessage message, int userId)
        {
            if (message.To.Length != 1)
            {
                throw new LogReadyException(LogTag.UnsupportedUsageOfSendMail, new { userId, emailType });
            }

            var toEmail = message.To.First().Address;

            if (toEmail.EndsWith("@test.com") && toEmail.EndsWith("@fake.fake"))
            {
                return;
            }

            QuotaValidationResult result = _quotaValidator.ValidateQuota(emailType, message, userId);

            if (result.IsValid)
            {
                await _sgTransport.DeliverAsync(message);

                await _sgLogger.LogEmailToDisk(emailType, message.To.First().Address, message.Subject, message.Html ?? message.Text, userId);
            }
            else
            {
                await SendQuotaExceedNotification(result, emailType, message, userId);
            }
        }
示例#6
0
        public bool SendEmail(string emailAddress, string body, string subject, EmailTypes emailType, string title = null)
        {
            MailMessage mail   = new MailMessage(config.Value.SMTPFromAddress, emailAddress);
            SmtpClient  client = new SmtpClient();

            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials           = new NetworkCredential(config.Value.SMTPUser, config.Value.SMTPUserPwd, config.Value.SMTPDomain);

            client.Host       = config.Value.SMTPServer;
            client.Port       = int.Parse(config.Value.SMTPPort);
            client.EnableSsl  = Convert.ToBoolean(config.Value.SMTPUseSSL);
            mail.Subject      = subject;
            mail.BodyEncoding = Encoding.UTF8;
            mail.IsBodyHtml   = true;
            mail.Body         = GetEmailBody(title, body, emailType);
            try
            {
                client.Send(mail);
                return(true);
            }
            catch (Exception ex)
            {
                LogError(ex, new { emailAddress, body, subject, emailType });
                return(false);
            }
        }
示例#7
0
        public bool CanSendNotification(EmailTypes type, ApiWhitelabelPublicUserModel userModel)
        {
            // Disabled users dont recieve emails
            if (userModel.Disabled)
            {
                return(false);
            }

            // Pending members dont recieve emails
            if (userModel.IsPending)
            {
                return(false);
            }

            // use platform settings
            if (OverwriteDefault == false)
            {
                return(true);
            }

            // all mails disabled
            if (DisableAllMails)
            {
                return(false);
            }

            if (type == EmailTypes.DailyDigest && DisableDailyDigest)
            {
                return(false);
            }

            if (type == EmailTypes.NewFeedPosComment && DisableNewFeedPostComment)
            {
                return(false);
            }

            if (type == EmailTypes.NewFeedPost && DisableNewFeedPost)
            {
                return(false);
            }

            if (type == EmailTypes.Assigned && DisableAssigned)
            {
                return(false);
            }

            if (type == EmailTypes.Mention && DisableMention)
            {
                return(false);
            }

            if (type == EmailTypes.AdminMails && DisableAdminMails)
            {
                return(false);
            }

            return(true);
        }
示例#8
0
 private Model.EmailTemplate FindByEmailTemplate(EmailTypes emailTypes, SortedList <string, string> replaceText)
 {
     Model.EmailTemplate emailTemplate = _EmailTemplateData.FindByTemplateName(Enum.GetName(typeof(EmailTypes), emailTypes));
     for (int i = 0; i < replaceText.Count(); i++)
     {
         emailTemplate.Body = emailTemplate.Body.Replace(replaceText.ElementAt(i).Key, replaceText.ElementAt(i).Value);
     }
     return(emailTemplate);
 }
        public static EmailTemplateNameModel TemplateNames(EmailTypes type)
        {
            if (!PathLib.ContainsKey(type))
            {
                throw new ArgumentOutOfRangeException($"Can not find type {type.ToString()} in Template names collection");
            }

            return(new EmailTemplateNameModel(PathLib[type]));
        }
        public static object Convert(EmailTypes type, string body)
        {
            if (ConvertLib.ContainsKey(type))
            {
                return(JsonConvert.DeserializeObject(body, ConvertLib[type]));
            }

            return(null);
        }
示例#11
0
 /// <summary>
 /// this fucntion will retrieve the email based on the given type
 /// </summary>
 /// <param name="type">the given type</param>
 /// <returns>the email string</returns>
 static String GetEmailPath(EmailTypes type)
 {
     return(type switch
     {
         EmailTypes.None => String.Empty,
         EmailTypes.ValidationEmail => "wwwroot/EmailStructures/validationEmail.txt",
         EmailTypes.ResetPassword => "wwwroot/EmailStructures/resetEmail.txt",
         _ => String.Empty,
     });
示例#12
0
        /// <summary>
        /// Sends the email of the specified type.
        /// </summary>
        /// <param name="emailType">Type of the email.</param>
        /// <param name="model">The model.</param>
        /// <param name="toAddresses">To addresses.</param>
        /// <returns></returns>
        public IProcessResult Send(EmailTypes emailType, object model, IEnumerable <string> toAddresses)
        {
            string emailTypeName = EnumHelper.Current.GetName(emailType);

            string emailAccount = GetEmailAccount(emailType);

            string body    = EmailTemplateEngine.Current.Generate(emailTypeName, model);
            string subject = EmailTemplateEngine.Current.Generate(String.Format("{0}Subject", emailTypeName), model);

            return(Send(emailAccount, body, subject, toAddresses));
        }
示例#13
0
        public Message(IEnumerable <string> to, string subject, string content, EmailTypes emailType = EmailTypes.None, string[] contentTokens = null, IFormFileCollection attachments = null)
        {
            To = new List <MailboxAddress>();

            To.AddRange(to.Select(x => new MailboxAddress(x)));
            Subject       = subject;
            Content       = content;
            ContentTokens = contentTokens;
            Attachments   = attachments;
            EmailType     = emailType;
        }
示例#14
0
 /**
  * @param validSince
  *            `validSince` is a <code>DateTime</code> object, it's the first
  *            time Pipl's crawlers found this data on the page.
  * @param address
  *            email address
  * @param addressMd5
  *            addressMd5
  * @param type
  *            type is one of "work", "personal".
  * @param @disposable
  *            Disposable: is this a disposable email such as guerrillamail.
  *            Only shown when true
  * @param @email_provider
  *            EmailProvider: is this a public provider such as gmail/outlook.
  *            Only shown when true
  */
 public Email(string address = null, string addressMd5 = null, EmailTypes? type = null, 
     bool? disposable = null, bool? email_provider = null,
     DateTime? validSince = null)
     : base(validSince)
 {
     this.Address = address;
     this.AddressMd5 = addressMd5;
     this.Type = type;
     this.Disposable = disposable;
     this.EmailProvider = email_provider;
 }
示例#15
0
        public void Test_GetEmailContent_HasExpectedOutput(EmailTypes emailType)
        {
            // given
            var subject = new EmailContentCreator();

            // when
            string testString = subject.GetEmailContent(emailType);

            // then
            Assert.AreEqual($"SUBJECT: {emailType.ToString()} | CONTENT: This is email of type: \"{emailType.ToString()}\".", testString);
        }
        public static CallResult <ComposeEmailViewModel> FromTemplate(IUnitOfWork db,
                                                                      IEmailService emailService,
                                                                      string orderId,
                                                                      CompanyDTO company,
                                                                      string byName,
                                                                      EmailTypes type,
                                                                      EmailAccountDTO emailAccountInfo)
        {
            try
            {
                ComposeEmailViewModel model = new ComposeEmailViewModel();

                orderId = OrderHelper.RemoveOrderNumberFormat(orderId);

                var order = db.Orders.GetAll().FirstOrDefault(q => q.AmazonIdentifier.ToLower() == orderId || q.CustomerOrderId == orderId);

                if (order != null)
                {
                    IEmailInfo info = emailService.GetEmailInfoByType(db,
                                                                      type,
                                                                      company,
                                                                      byName,
                                                                      order?.AmazonIdentifier,
                                                                      new Dictionary <string, string>(),
                                                                      null,
                                                                      null);

                    model = ComposeEmailViewModel.BuildFrom(db, info);
                }

                model.FromName  = emailAccountInfo.DisplayName;
                model.FromEmail = emailAccountInfo.FromEmail;

                if (!StringHelper.ContainsNoCase(model.Subject, "[Important]") &&
                    (model.Market == MarketType.Amazon ||
                     model.Market == MarketType.AmazonEU ||
                     model.Market == MarketType.AmazonAU ||
                     model.Market == MarketType.None))
                {
                    var existEmailFromCustomer = db.Emails.GetAll().Any(e => e.From == model.ToEmail);
                    if (!existEmailFromCustomer)
                    {
                        model.Subject = "[Important] " + model.Subject;
                    }
                }

                return(CallResult <ComposeEmailViewModel> .Success(model));
            }
            catch (Exception ex)
            {
                return(CallResult <ComposeEmailViewModel> .Fail(ex.Message, ex));
            }
        }
示例#17
0
        // ReSharper disable MemberCanBePrivate.Global
        // ReSharper disable MemberCanBeProtected.Global
        // ReSharper disable UnusedMember.Global
        // ReSharper disable UnusedMethodReturnValue.Global
        // ReSharper disable UnusedAutoPropertyAccessor.Global
        // ReSharper disable UnassignedField.Global

        #endregion ReSharper disable

        // These are public so they can be used by the WebService

        public static List <SimpleListItem> GetEmailTypes()
        {
            return(new List <SimpleListItem> {
                new SimpleListItem {
                    Value = Empty, Text = "<no type>"
                }
            }
                   .Union(EmailTypes.GetAllData().OrderBy(r => r.Description).Select(r =>
                                                                                     new SimpleListItem {
                Value = r.EmailTypeCode, Text = r.Description
            })).ToList());
        }
        /// <summary>
        /// Assign DisplayName,From Email Id and Subject based on the email type.
        /// </summary>
        /// <param name="emailTypes"></param>
        /// <param name="body"></param>
        public void AssignMailSettings(EmailTypes emailTypes, string body)
        {
            switch (emailTypes)
            {
            case EmailTypes.AdviserRegistration:
                this.From    = new MailAddress("*****@*****.**", "MoneyTouch Adviser Registration");
                this.Subject = "MoneyTouch Adviser Registration";
                break;

            case EmailTypes.AdviserRMAccount:
                this.From    = new MailAddress("*****@*****.**", "MoneyTouch");
                this.Subject = "MoneyTouch Account Details";
                break;

            case EmailTypes.ForgotPassword:
                this.From    = new MailAddress("*****@*****.**", "MoneyTouch");
                this.Subject = "MoneyTouch Forgot Password";
                break;

            case EmailTypes.CustomerCredentials:
                this.From    = new MailAddress("*****@*****.**", "MoneyTouch");
                this.Subject = "MoneyTouch Customer Account Credentials";
                break;

            case EmailTypes.ResetPassword:
                this.From    = new MailAddress("*****@*****.**", "MoneyTouch");
                this.Subject = "MoneyTouch Reset Password";
                break;

            case EmailTypes.AdviserRegistrationNotification:
                this.To.Clear();
                this.CC.Clear();
                string   toMailIdString = ConfigurationManager.AppSettings["AdminNotificationTo"].ToString();
                string[] toMailIds      = toMailIdString.Split(',');
                foreach (string mailId in toMailIds)
                {
                    this.To.Add(mailId);
                }

                string   CCMailIdString = ConfigurationManager.AppSettings["AdminNotificationCC"].ToString();
                string[] CCMailIds      = CCMailIdString.Split(',');
                foreach (string mailId in CCMailIds)
                {
                    this.CC.Add(mailId);
                }

                this.From    = new MailAddress("*****@*****.**", "MoneyTouch");
                this.Subject = "MoneyTouch Adviser Registration";
                break;
            }
            this.Body = body;
        }
示例#19
0
        private string GetEmailAccount(EmailTypes emailType)
        {
            switch (emailType)
            {
            case EmailTypes.ConfirmEmail:
            case EmailTypes.ResetPassword:
                return(EmailAccounts.Support);

            case EmailTypes.AppMessage:
            default:
                return(EmailAccounts.AppMessenger);
            }
        }
        public void Test_SendEmail_CallsEmailContentCreatorWithRightEmailType(EmailTypes emailTypes)
        {
            // given
            Mock <IEmailContentCreator> emailContentCreatorMock = new Mock <IEmailContentCreator>();
            Mock <IEmailSendingService> emailSendingServiceMock = new Mock <IEmailSendingService>();
            var         emailSender = new EmailSender(emailContentCreatorMock.Object, emailSendingServiceMock.Object);
            ITranslator translator  = Mock.Of <ITranslator>();

            // when
            emailSender.SendEmail(emailTypes, translator);

            // then
            emailContentCreatorMock.Verify(_ => _.GetEmailContent(It.Is <EmailTypes>(x => x == emailTypes)));
        }
示例#21
0
        public void TestUpdatePerson()
        {
            Guid                  guid      = new Guid("2E5DA098-91D6-40C4-95BC-98B206F8A36F");
            string                updatedBy = "TsetUserupdate";
            PersonDTO             person    = new PersonDTO();
            PersonEmailDTO        email     = new PersonEmailDTO();
            PersonPhoneDTO        phone     = new PersonPhoneDTO();
            PersonAddressDTO      address   = new PersonAddressDTO();
            List <PersonPhoneDTO> phones    = new List <PersonPhoneDTO>();

            phone.PhoneType = 1;
            phone.Phone     = "9907864345";
            phones.Add(phone);

            address.AddressID     = 1234;
            address.AddressNumber = 1;
            address.AddressType   = 1;
            address.IsPrimary     = true;
            address.ShipToName    = "TestUser";

            List <PersonAddressDTO> addres = new List <PersonAddressDTO>();

            addres.Add(address);
            List <PersonEmailDTO> emails = new List <PersonEmailDTO>();

            email.Email = "*****@*****.**";
            List <EmailTypes> emailtype = new List <EmailTypes>();

            person.Emails   = emails;
            person.PersonID = 8234;


            EmailTypes type = (EmailTypes)Enum.ToObject(typeof(EmailTypes), 1);

            email.EmailType = type;
            emails.Add(email);

            emailtype.Add(type);

            person.MasterGuid = Guid.Parse("2E5DA098-91D6-40C4-95BC-98B206F8A36F");
            person.Phones     = phones;
            person.Addresses  = addres;
            person.FirstName  = "TestUserupdate";
            person.MiddleName = "TestCase";
            person.LastName   = "Kaplan123";
            person.Title      = "Miss";
            bool Republish = false;
            var  result    = MessageAdapter.Utilities.Utility.UpdatePerson(guid, person, updatedBy, Republish).Result;
        }
示例#22
0
        public void TestCreatePerson()
        {
            PersonDTO             person  = new PersonDTO();
            PersonEmailDTO        email   = new PersonEmailDTO();
            PersonPhoneDTO        phone   = new PersonPhoneDTO();
            PersonAddressDTO      address = new PersonAddressDTO();
            List <PersonPhoneDTO> phones  = new List <PersonPhoneDTO>();

            phone.PhoneType = 1;
            phone.Phone     = "9907864345";
            phones.Add(phone);

            address.AddressID     = 1234;
            address.AddressNumber = 1;
            address.AddressType   = 1;
            address.IsPrimary     = true;
            address.ShipToName    = "TestUser";

            List <PersonAddressDTO> addres = new List <PersonAddressDTO>();

            addres.Add(address);
            List <PersonEmailDTO> emails = new List <PersonEmailDTO>();

            email.Email = "*****@*****.**";

            List <EmailTypes> emailtype = new List <EmailTypes>();
            EmailTypes        type      = (EmailTypes)Enum.ToObject(typeof(EmailTypes), 1);

            email.EmailType = type;
            emails.Add(email);

            emailtype.Add(type);

            person.Emails     = emails;
            person.PersonID   = 8234;
            person.PersonGuid = Guid.Parse("f2f224db-2c8a-456f-b025-f5955cd16051");
            person.MasterGuid = Guid.Parse("f2f224db-2c8a-456f-b025-f5955cd16051");

            person.Addresses  = addres;
            person.Phones     = phones;
            person.FirstName  = "TestUser";
            person.MiddleName = "TestCase";
            person.LastName   = "Kaplan123";
            person.Title      = "Ms";
            string createdBy = "TestUser";
            bool   Republish = false;
            var    result    = MessageAdapter.Utilities.Utility.CreatePersonAsync(person, createdBy, Republish).Result;
        }
示例#23
0
        private string PrepeareEmail(EmailTypes emailTypeToSend, string templateHtml, string speakerName, string sessionTitle)
        {
            string speakerFirstName = speakerName.Split(' ').First();
            string html             = templateHtml.Replace(configuration.Email_SpeakerNamePlaceholder, speakerFirstName)
                                      .Replace(configuration.Email_SessionTitlePlaceholder, sessionTitle);

            var directory = Path.Combine(configuration.SentEmails_OutputDirectory, emailTypeToSend.ToString());

            Directory.CreateDirectory(directory);

            string path = Path.Combine(directory, speakerName) + ".html";

            File.WriteAllText(path, html);

            return(html);
        }
示例#24
0
        public bool SendEmail(EmailTypes type, ITranslator translator)
        {
            if (translator == null)
            {
                throw new ArgumentNullException(nameof(translator));
            }
            string emailContent      = myEmailContentCreator.GetEmailContent(type);
            string translatedContent = translator.Translate(emailContent);

            if (myEmailSendingService.Send(translatedContent))
            {
                EmailSent?.Invoke(this, EventArgs.Empty);
                return(true);
            }
            return(false);
        }
示例#25
0
        private Result <EmailEntity> GetMail(EmailTypes type)
        {
            BaseSpecification <EmailEntity> baseSpecification = new BaseSpecification <EmailEntity>();

            baseSpecification.AddFilter(x => x.Type == type);

            EmailEntity mail = _mailRepository.SingleOrDefault(baseSpecification);

            if (mail == null)
            {
                _logger.LogError($"No mail active mail with type {type}");
                return(Result.Fail <EmailEntity>("no_mail", "No Mail"));
            }

            return(Result.Ok(mail));
        }
示例#26
0
        public QuotaValidationResult ValidateQuota(EmailTypes emailType, SendGridMessage message, int userId)
        {
            switch (emailType)
            {
            case EmailTypes.EmailValidation:            return(ValidateEmailVerificationMessage(message, userId));

            case EmailTypes.PasswordRecovery:           return(ValidatePasswordRecoveryMessage(message, userId));

            case EmailTypes.MessageNotification:        return(ValidateMessageNotification(message, userId));

            case EmailTypes.CustomMail:                 return(QuotaValidationResult.Success);

            case EmailTypes.ContactUsNotification:

            default: throw new LogReadyException(LogTag.UnexpectedEmailTypeOnQuotaValidator, new { EmailType = emailType });
            }
        }
 public static MailAddress GetMailAddress(EmailTypes type)
 {
     if (type == EmailTypes.Direct)
     {
         return(new MailAddress("*****@*****.**", "علیرضا رضائی"));
     }
     else if (type == EmailTypes.Newsletter)
     {
         return(new MailAddress("*****@*****.**", "خبرنامه وبسایت علیرضا رضائی"));
     }
     else if (type == EmailTypes.Sales)
     {
         return(new MailAddress("*****@*****.**", "سفارشات وبسایت علیرضا رضائی"));
     }
     else //if (type == EmailTypes.NoReply || ...)
     {
         return(new MailAddress("*****@*****.**", "وبسایت علیرضا رضائی"));
     }
 }
示例#28
0
 public static MailAddress GetMailAddress(EmailTypes type)
 {
     if (type == EmailTypes.Info)
     {
         return(new MailAddress("*****@*****.**", "های شاپ"));
     }
     else if (type == EmailTypes.Newsletter)
     {
         return(new MailAddress("*****@*****.**", "های شاپ"));
     }
     else if (type == EmailTypes.NoReply)
     {
         return(new MailAddress("*****@*****.**", "های شاپ"));
     }
     else
     {
         return(new MailAddress("*****@*****.**", "های شاپ"));
     }
 }
示例#29
0
 public static MailAddress GetMailAddress(EmailTypes type)
 {
     if (type == EmailTypes.Direct)
     {
         return(new MailAddress("*****@*****.**", "Display name"));
     }
     else if (type == EmailTypes.Newsletter)
     {
         return(new MailAddress("*****@*****.**", "Display name"));
     }
     else if (type == EmailTypes.Sales)
     {
         return(new MailAddress("*****@*****.**", "Display name"));
     }
     else //if (type == EmailTypes.NoReply || ...)
     {
         return(new MailAddress("*****@*****.**", "Display name"));
     }
 }
        public virtual ActionResult ComposeEmailFromTemplate(string orderNumber,
                                                             EmailTypes type,
                                                             long?replyToId)
        {
            LogI("ComposeEmailFromTemplate, orderNumber=" + orderNumber + ", type=" + type.ToString() + ", replyToEmailId=" + replyToId);

            var company      = AccessManager.Company;
            var smtpSettings = CompanyHelper.GetSmtpSettings(company);
            var byName       = AccessManager.UserName;

            var result = ComposeEmailViewModel.GetTemplateInfo(Db,
                                                               EmailService,
                                                               company,
                                                               byName,
                                                               type,
                                                               smtpSettings,
                                                               orderNumber,
                                                               replyToId);

            return(View("ComposeEmail", result.Data));
        }
示例#31
0
        public async Task SendAsync(EmailTypes from,
                                    string to,
                                    string subject,
                                    string body,
                                    bool isBodyHtml = true,
                                    string cc       = null,
                                    string bcc      = null,
                                    AttachmentCollection attachments = null)
        {
            //1- Set Email Message
            var mailMessage = new MailMessage();

            mailMessage.From = EmailSettings.GetMailAddress(from);
            mailMessage.To.Add(to);
            mailMessage.Subject    = subject;
            mailMessage.IsBodyHtml = isBodyHtml;
            mailMessage.Body       = body;
            if (cc != null)
            {
                mailMessage.CC.Add(cc);
            }
            if (bcc != null)
            {
                mailMessage.Bcc.Add(bcc);
            }
            if (attachments != null)
            {
                foreach (var attachment in attachments)
                {
                    mailMessage.Attachments.Add(attachment);
                }
            }


            //2- Set SmtpClient
            var smtp = EmailSettings.GetSmtpClient(from);

            //3- Send Email
            await smtp.SendMailAsync(mailMessage);
        }
示例#32
0
        public async Task SendEmail(EmailTypes emailtype, TransmissionPayload payload)
        {
            var template = await GetTemplate(emailtype.ToString());

            var transmission = new Transmission
            {
                Recipients = payload.Destinations.Select(x => new Recipient
                {
                    Address          = new Address(x.DestinationEmail),
                    SubstitutionData = x.SubstitutionData
                }).ToList(),
                Content =
                {
                    Html        = template.Body,
                    From        = new Address(template.SourceEmail),
                    Subject     = template.Subject,
                    Attachments = payload.Attachments.ToList()
                }
            };
            var client = new Client(_clientKey);
            await client.Transmissions.Send(transmission);
        }
        private void PopulateEmailTypes()
        {
            var emailTypesData = HttpHelper.Get<EmailTypesData>(serviceBaseUri+"/EmailTypes");

            var emailTypes = new EmailTypes();
            mapper.MapList(emailTypesData, emailTypes, typeof(EmailType));
            ViewData["emailTypes"] = emailTypes;
        }
示例#34
0
 internal void SetMailOptionMenu(Gtk.OptionMenu optMenu, EmailTypes type)
 {
     if( (type & EmailTypes.work) == EmailTypes.work)
        {
     optMenu.SetHistory(0);
     return;
        }
        if( (type & EmailTypes.personal) == EmailTypes.personal)
        {
     optMenu.SetHistory(1);
     return;
        }
        optMenu.SetHistory(2);
 }
示例#35
0
 internal void PopulateEmailType(EmailTypes types)
 {
     foreach(Email e in currentContact.GetEmailAddresses())
        {
     if( types != EmailTypes.preferred )
     {
      if( (e.Types & EmailTypes.preferred)==EmailTypes.preferred)
      {
       continue;
      }
     }
     if( (e.Types & types) != types)
     {
      continue;
     }
     if(emailOne == null)
     {
      emailOne = e;
      MOneEntry.Text = emailOne.Address;
      SetMailOptionMenu(MOneOptionMenu, emailOne.Types);
     }
     else if(emailTwo == null)
     {
      emailTwo = e;
      MTwoEntry.Text = e.Address;
      SetMailOptionMenu(MTwoOptionMenu, emailTwo.Types);
     }
     else if(emailThree == null)
     {
      emailThree = e;
      MThreeEntry.Text = e.Address;
      SetMailOptionMenu(MThreeOptionMenu, emailThree.Types);
     }
     else if(emailFour == null)
     {
      emailFour = e;
      MFourEntry.Text = e.Address;
      SetMailOptionMenu(MFourOptionMenu, emailFour.Types);
     }
        }
 }
 public EmailTypesCreateOrUpdateCommand(EmailTypes ent)
 {
     this.ent = ent;
 }