Ejemplo n.º 1
0
        /// <summary>
        /// Method Name     : AddRecipients
        /// Author          : Jitendra Garg
        /// Creation Date   : 15 Jan 2018
        /// Purpose         : Adds recipients to the mail object (Reduces cognitive complexity of AddMessage function
        /// Revision        :
        /// </summary>
        private void AddRecipients()
        {
            string[] mailAddress = null;

            if (!string.IsNullOrEmpty(ToRecipients))
            {
                mailAddress = ToRecipients.Split(',');
                foreach (string strRecp in mailAddress)
                {
                    emailMessage.To.Add(new MailAddress(strRecp));
                }
            }
            if (!string.IsNullOrEmpty(BccRecipients))
            {
                mailAddress = BccRecipients.Split(',');
                foreach (string strRecp in mailAddress)
                {
                    emailMessage.Bcc.Add(new MailAddress(strRecp));
                }
            }

            if (!string.IsNullOrEmpty(CcRecipients))
            {
                mailAddress = CcRecipients.Split(',');
                foreach (string strRecp in mailAddress)
                {
                    emailMessage.CC.Add(new MailAddress(strRecp));
                }
            }
        }
Ejemplo n.º 2
0
        private IList <MapiRecipientDescription> CollectRecipientData()
        {
            var list = new List <MapiRecipientDescription>();

            list.AddRange(Recipients.GetRecipientObjects());
            list.AddRange(CcRecipients.GetRecipientObjects());
            list.AddRange(BccRecipients.GetRecipientObjects());
            return(list);
        }
        public void AddBCCRecipients(IEnumerable <SourceAddress> recipients)
        {
            foreach (var recipient in recipients)
            {
                BccRecipients.AddRecipient(mailbox.Find(recipient));
            }

            if (BccRecipients.Recipients.Count > 0)
            {
                IsCCBCCFieldOpen = true;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Send the <see cref="Mail"/> message with <see cref="Attachments"/> to the <see cref="ToRecipients"/>,
        /// <see cref="CcRecipients"/> and <see cref="BccRecipients"/> using the specified <see cref="SmtpServer"/>.
        /// </summary>
        public void Send()
        {
            MailMessage emailMessage = new MailMessage
            {
                From       = new MailAddress(m_from),
                Subject    = Subject,
                Body       = Body,
                IsBodyHtml = IsBodyHtml
            };

            #pragma warning disable CS8602
            if (!string.IsNullOrEmpty(m_toRecipients))
            {
                // Add the specified To recipients for the mail message.
                foreach (string toRecipient in m_toRecipients.Split(';', ','))
                {
                    emailMessage.To.Add(toRecipient.Trim());
                }
            }

            if (!string.IsNullOrEmpty(CcRecipients))
            {
                // Add the specified CC recipients for the mail message.
                foreach (string ccRecipient in CcRecipients.Split(';', ','))
                {
                    emailMessage.CC.Add(ccRecipient.Trim());
                }
            }

            if (!string.IsNullOrEmpty(BccRecipients))
            {
                // Add the specified BCC recipients for the mail message.
                foreach (string bccRecipient in BccRecipients.Split(';', ','))
                {
                    emailMessage.Bcc.Add(bccRecipient.Trim());
                }
            }

            if (!string.IsNullOrEmpty(Attachments))
            {
                // Attach the specified files to the mail message.
                foreach (string attachment in Attachments.Split(';', ','))
                {
                    // Create the file attachment for the mail message.
                    Attachment         data   = new Attachment(attachment.Trim(), MediaTypeNames.Application.Octet);
                    ContentDisposition header = data.ContentDisposition;

                    // Add time stamp information for the file.
                    header.CreationDate     = File.GetCreationTime(attachment);
                    header.ModificationDate = File.GetLastWriteTime(attachment);
                    header.ReadDate         = File.GetLastAccessTime(attachment);

                    emailMessage.Attachments.Add(data); // Attach the file.
                }
            }
            #pragma warning restore CS8602

            try
            {
                // Send the mail.
                Client?.Send(emailMessage);
            }
            finally
            {
                // Clean-up.
                emailMessage.Dispose();
            }
        }
 public void ClearRecipients()
 {
     ToRecipients.ClearRecipients();
     CcRecipients.ClearRecipients();
     BccRecipients.ClearRecipients();
 }
        public void AddBCCRecipient(SourceAddress recipient)
        {
            BccRecipients.AddRecipient(mailbox.Find(recipient));

            IsCCBCCFieldOpen = true;
        }