Exemple #1
0
        public Boolean SendMessageWithQP()
        {
            using (var MailMessage = new MailMessage())
            {
                MailMessage.From       = new MailAddress(FromAddress);
                MailMessage.Subject    = Subject;
                MailMessage.Body       = Body;
                MailMessage.Priority   = MailPriority;
                MailMessage.IsBodyHtml = IsBodyHTML;


                string[] toAddressSplit = ToAddress.Split(';');
                var      toContacts     = (from item in toAddressSplit where !String.IsNullOrWhiteSpace(item) select item).ToArray();
                if (toContacts.Length > 0)
                {
                    MailMessage.To.Add(String.Join(",", toContacts));
                }


                // Add the To CC Email Address in Bulk
                string[] toCCAddressSplit = ToAddressCC.Split(';');
                var      ccContacts       = (from item in toCCAddressSplit where !String.IsNullOrWhiteSpace(item) select item).ToArray();
                if (ccContacts.Length > 0)
                {
                    MailMessage.CC.Add(String.Join(",", ccContacts));
                }

                // Add message attachments in bulk
                if (Attachments != null && Attachments != string.Empty)
                {
                    string[] attachmentsTemp = Attachments.Split(';');

                    foreach (string attachTemp in attachmentsTemp)
                    {
                        Attachment attach = new Attachment(attachTemp);
                        attach.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;
                        MailMessage.Attachments.Add(new Attachment(attachTemp));
                    }
                }


                using (SmtpClient client = new SmtpClient(SMTPServerName))
                {
                    client.Send(MailMessage);
                    // MailMessage.Attachments.Dispose();
                }
                return(true);
            }
        }
Exemple #2
0
        /// <summary>
        /// save the message.
        /// </summary>
        /// <returns></returns>
        public Boolean SaveMessage(string DocumentPath)
        {
            using (var MailMessage = new MailMessage())
            {
                MailMessage.From       = new MailAddress(FromAddress);
                MailMessage.Subject    = Subject;
                MailMessage.Body       = Body;
                MailMessage.Priority   = MailPriority;
                MailMessage.IsBodyHtml = IsBodyHTML;


                string[] toAddressSplit = ToAddress.Split(';');
                var      toContacts     = (from item in toAddressSplit where !String.IsNullOrWhiteSpace(item) select item).ToArray();
                if (toContacts.Length > 0)
                {
                    MailMessage.To.Add(String.Join(",", toContacts));
                }


                // Add the To CC Email Address in Bulk
                string[] toCCAddressSplit = ToAddressCC.Split(';');
                var      ccContacts       = (from item in toCCAddressSplit where !String.IsNullOrWhiteSpace(item) select item).ToArray();
                if (ccContacts.Length > 0)
                {
                    MailMessage.CC.Add(String.Join(",", ccContacts));
                }

                // Add message attachments in bulk
                if (Attachments != null && Attachments != string.Empty)
                {
                    string[] attachmentsTemp = Attachments.Split(';');

                    foreach (string attachTemp in attachmentsTemp)
                    {
                        MailMessage.Attachments.Add(new Attachment(attachTemp));
                    }
                }


                using (SmtpClient client = new SmtpClient(SMTPServerName))
                {
                    client.PickupDirectoryLocation = DocumentPath;
                    client.DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    client.Send(MailMessage);
                }
                return(true);
            }
        }