Exemplo n.º 1
0
        public void Send(MailRequestSetting mailSetting)
        {
            //Validation mailSetting
            Contract.NotNull(mailSetting, "mailSetting");
            Contract.NotNull(mailSetting.From, "From");
            Contract.NotNull(mailSetting.To, "To");
            Contract.Assert(mailSetting.To.Count() > 0, "To");

            DateTime now      = DateTime.Now;
            string   filename = String.Format("{0:yyyyMMddHHmmss}_{1}.txt", now, Guid.NewGuid().ToString().Substring(0, 6));

            //Format property to output
            string to  = String.Join(",", mailSetting.To.Select(t => String.Format("<{0}/{1}>", t.Address, t.DisplayName)));
            string cc  = mailSetting.Cc == null ? "" : String.Join(",", mailSetting.Cc.Select(t => String.Format("<{0}/{1}>", t.Address, t.DisplayName)));
            string bcc = mailSetting.Bcc == null ? "" : String.Join(",", mailSetting.Bcc.Select(t => String.Format("<{0}/{1}>", t.Address, t.DisplayName)));

            //Modify content to output file
            StringBuilder content = new StringBuilder();

            content.AppendFormat("RequestTime: {0}", now.ToString("yyyy/MM/dd HH:mm:ss"));
            content.AppendLine().AppendFormat("From: {0}", mailSetting.From.Address);
            content.AppendLine().AppendFormat("To: {0}", to);
            content.AppendLine().AppendFormat("CC: {0}", cc);
            content.AppendLine().AppendFormat("BCC: {0}", bcc);
            content.AppendLine().AppendFormat("Subject: {0}", mailSetting.Subject);
            content.AppendLine().AppendFormat("Body: {0}{1}", System.Environment.NewLine, mailSetting.Body);

            //Output File
            File.WriteAllText(System.IO.Path.Combine(outputDirectory, filename), content.ToString());
        }
Exemplo n.º 2
0
        public void Send(MailRequestSetting mailSetting)
        {
            //Validation mailSetting
            Contract.NotNull(mailSetting, "mailSetting");
            Contract.NotNull(mailSetting.From, "From");
            Contract.NotNull(mailSetting.To, "To");
            Contract.Assert(mailSetting.To.Count() > 0, "To");
            Contract.NotEmpty(mailSetting.Subject, "Subject");

            //Format property to output
            string to  = String.Join(",", mailSetting.To.Select(t => String.Format("<{0}/{1}>", t.Address, t.DisplayName)));
            string cc  = mailSetting.Cc == null ? "" : String.Join(",", mailSetting.Cc.Select(t => String.Format("<{0}/{1}>", t.Address, t.DisplayName)));
            string bcc = mailSetting.Bcc == null ? "" : String.Join(",", mailSetting.Bcc.Select(t => String.Format("<{0}/{1}>", t.Address, t.DisplayName)));

            StringBuilder content = new StringBuilder();

            content.AppendLine("-----------------------------------------------------");
            content.Append("このメールは固定アドレスメール機能により送信されました。").AppendLine();
            content.AppendFormat("To: {0}", to).AppendLine();
            content.AppendFormat("CC: {0}", cc).AppendLine();
            content.AppendFormat("BCC: {0}", bcc).AppendLine();
            content.AppendLine("-----------------------------------------------------");

            content.AppendLine().AppendLine();

            content.Append(mailSetting.Body);

            //Create fixAddress To from SmtpMailConfiguration
            List <EmailAddress> fixTo = new List <EmailAddress>();

            smtpConfig.FixAddresses.ForEach(f => fixTo.Add(new EmailAddress(f)));
            MailRequestSetting newSetting = new MailRequestSetting(mailSetting.From, fixTo, mailSetting.Subject, content.ToString(), properties: mailSetting.Properties);

            new SmtpMailSender(smtpConfig, logcontext).Send(newSetting);
        }
 public void Send(MailRequestSetting mailSetting)
 {
     Contract.NotNull(mailSetting, "mailSetting");
     Contract.NotNull(mailSetting.From, "From");
     Contract.NotNull(mailSetting.To, "To");
     Contract.Assert(mailSetting.To.Count() > 0, "To");
     Contract.NotEmpty(mailSetting.Subject, "Subject");
     SendMail(mailSetting.From, mailSetting.To, mailSetting.Subject, mailSetting.Body, mailSetting.Cc, mailSetting.Bcc);
 }