Пример #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));
                }
            }
        }
Пример #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 AddCCRecipients(IEnumerable <SourceAddress> recipients)
        {
            foreach (var recipient in recipients)
            {
                CcRecipients.AddRecipient(mailbox.Find(recipient));
            }

            if (CcRecipients.Recipients.Count > 0)
            {
                IsCCBCCFieldOpen = true;
            }
        }
Пример #4
0
        /// <summary>
        ///     Creates a <c>BulkDeleteRequest</c>.
        /// </summary>
        /// <param name="queries">The queries which returns the records to delete.</param>
        /// <returns>A <c>BulkDeleteRequest</c> object.</returns>
        private BulkDeleteRequest CreateBulkDeleteRequest(IEnumerable <QueryExpression> queries)
        {
            var bulkDeleteRequest = new BulkDeleteRequest
            {
                JobName               = String.IsNullOrEmpty(BulkDeleteOperationName) ? "Bulk Delete - " + DateTime.Now.ToString("g") : BulkDeleteOperationName,
                QuerySet              = queries.ToArray(),
                StartDateTime         = StartTime == DateTime.MinValue ? DateTime.Now : StartTime,                      // Default is start immediately
                RecurrencePattern     = RecurrencePattern ?? String.Empty,                                              // Default is none (empty)
                SendEmailNotification = SendEmailNotification,                                                          // Default is false
                ToRecipients          = ToRecipients == null ? new Guid[0] : ToRecipients.Select(Guid.Parse).ToArray(), // Default is none (empty)
                CCRecipients          = CcRecipients == null ? new Guid[0] : CcRecipients.Select(Guid.Parse).ToArray(), // Default is none (empty)
            };

            return(bulkDeleteRequest);
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExchangeEmailMessage" /> class.
        /// </summary>
        /// <param name="email">The <see cref="ExchangeMessage" /> retrieved from the Exchange server.</param>
        /// <exception cref="ArgumentNullException"><paramref name="email" /> is null.</exception>
        internal ExchangeEmailMessage(ExchangeMessage email)
        {
            if (email == null)
            {
                throw new ArgumentNullException(nameof(email));
            }

            ExchangeId       = email.Id;
            DateTimeSent     = email.DateTimeSent;
            DateTimeReceived = email.DateTimeReceived;
            Subject          = email.Subject;
            Body             = email.Body;

            if (!string.IsNullOrEmpty(email.From?.Address))
            {
                try
                {
                    FromAddress = new MailAddress(email.From?.Address, email.From?.Name);
                }
                catch (FormatException)
                {
                    // Invalid From address.
                }
            }

            foreach (EmailAddress toRecipient in email.ToRecipients)
            {
                ToRecipients.Add(new MailAddress(toRecipient.Address, toRecipient.Name));
            }

            foreach (EmailAddress ccRecipient in email.CcRecipients)
            {
                CcRecipients.Add(new MailAddress(ccRecipient.Address, ccRecipient.Name));
            }

            if (email.HasAttachments)
            {
                foreach (FileAttachment file in email.Attachments)
                {
                    Attachments.Add(new ExchangeEmailAttachment(file));
                }
            }

            foreach (var header in email.InternetMessageHeaders)
            {
                Headers[header.Name] = header.Value;
            }
        }
Пример #6
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 AddCCRecipient(SourceAddress recipient)
        {
            CcRecipients.AddRecipient(mailbox.Find(recipient));

            IsCCBCCFieldOpen = true;
        }