コード例 #1
0
 /// <summary>
 ///     Get a mail message instead of sending the direct email.
 /// </summary>
 /// <param name="mailingTos">Csv email address</param>
 /// <param name="subject"></param>
 /// <param name="body"></param>
 /// <param name="ccMails">cc email addresses as csv. Will be added to the To,CC, or Bcc List based on given type.</param>
 /// <param name="type">cc emails addresses as csv. Will be added to the To,CC, or Bcc List based on given type.</param>
 /// <param name="attachments"></param>
 /// <param name="searchForComma">Checks for comma in the emails and split it if possible.</param>
 /// <param name="isHtml"></param>
 /// <exception cref="Exception">
 ///     If mailer is not configured properly then : "Mailer is not configured correctly. Please
 ///     check credentials , host config and mailing address maybe empty or not declared."
 /// </exception>
 public MailMessage GetMailMessage(
     string[] mailingTos,
     string subject,
     string body,
     string[] ccMails,
     List <Attachment> attachments = null,
     MailingType type    = MailingType.RegularMail,
     bool searchForComma = false,
     bool isHtml         = true)
 {
     if (IsConfigured && !mailingTos.IsEmpty())
     {
         var mail = GetNewMailMessage(subject, body, isHtml);
         MailingAddressAttach(ref mail, mailingTos, ccMails, type);
         if (attachments != null)
         {
             foreach (var attachment in attachments)
             {
                 mail.Attachments.Add(attachment);
             }
         }
         return(mail);
     }
     throw new Exception(
               "Mailer is not configured correctly. Please check credentials , host config and mailing address maybe empty or not declared.");
 }
コード例 #2
0
        /// <summary>
        /// Creates a mailing and returns its id. The created mailing will include all the default settings of the account such as the default template, the default mailing list (target group), sender address etc...
        /// </summary>
        /// <param name="name">	Name of the mailing. The name must be unique within the account. The name length must be in the range from 3 to 64 and should only contain alphanumeric characters or spaces.</param>
        /// <param name="subject">The subject of the mailing. The length of the subject must not exceed 255 characters. The subject is not allowed to be empty. ISO Control characters are forbidden in the subject.</param>
        /// <param name="type">The type of the mailing</param>
        /// <returns>The ID of the newly created mailing</returns>
        public long CreateMailing(string name, string subject, MailingType type)
        {
            QueryParameters parameters = new QueryParameters();

            parameters.Add("name", name);
            parameters.Add("subject", subject);
            parameters.Add("type", type);

            ResponseWrapper response = Post("mailings", parameters, null);

            return(SerializationUtils <long> .FromXmlString(response.Body, "id"));
        }
コード例 #3
0
 /// <summary>
 ///     Quickly send an emailAddress.
 /// </summary>
 /// <param name="to"></param>
 /// <param name="subject"></param>
 /// <param name="body"></param>
 /// <param name="type">cc emails addresses as csv. Will be added to the To,CC, or Bcc List based on given type.</param>
 /// <param name="searchForComma">Checks for comma in the emails and split it if possible.</param>
 /// <param name="attachments"></param>
 /// <param name="isAsync">Send emails asynchronously.</param>
 /// <param name="isHtml">Is email body is going to be html or not. By default Html.</param>
 /// <param name="userToken"></param>
 /// <param name="sendCompletedEventHandler"></param>
 /// <exception cref="Exception"></exception>
 public void QuickSend(
     string to,
     string subject,
     string body,
     MailingType type              = MailingType.RegularMail,
     bool searchForComma           = true,
     List <Attachment> attachments = null,
     bool isAsync     = true,
     bool isHtml      = true,
     object userToken = null,
     SendCompletedEventHandler sendCompletedEventHandler = null)
 {
     SendWithAttachments(to, subject, body, attachments, type, searchForComma, isAsync, isHtml, userToken, sendCompletedEventHandler);
 }
コード例 #4
0
        /// <summary>
        ///     Sends mail asynchronously.
        /// </summary>
        /// <param name="to">Comma to seperate multiple emailAddress addresses.</param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="from"></param>
        /// <param name="password"></param>
        /// <param name="type">Regular, CC, BCC</param>
        public void QuickSend(string to, string subject, string body, string from, string password,
                              MailingType type = MailingType.RegularMail)
        {
            var emailBack    = SenderEmailAddress;
            var passwordBack = SenderEmailPassword;

            SenderEmailAddress  = from;
            SenderEmailPassword = password;
            SetupCredentials();
            QuickSend(to, subject, body);

            SenderEmailAddress  = emailBack;
            SenderEmailPassword = passwordBack;
            SetupCredentials();
        }
コード例 #5
0
 /// <summary>
 ///     Add email address to, cc, or bcc list based on type chosen.
 /// </summary>
 /// <param name="mail"></param>
 /// <param name="mailTo">Email address add to ToList, CCList, BccList based on chosen type.</param>
 /// <param name="type">Email address add to ToList, CCList, BccList based on chosen type.</param>
 public void MailingAddressAttach(ref MailMessage mail, string mailTo, MailingType type)
 {
     if (type == MailingType.RegularMail)
     {
         mail.To.Add(new MailAddress(mailTo));
     }
     else if (type == MailingType.CarbonCopy)
     {
         mail.CC.Add(new MailAddress(mailTo));
     }
     else
     {
         mail.Bcc.Add(new MailAddress(mailTo));
     }
 }
コード例 #6
0
        /// <summary>
        ///     Get a mail message instead of sending the direct email.
        /// </summary>
        /// <param name="mailingTos">Csv email address</param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="ccMails">cc email addresses as csv. Will be added to the To,CC, or Bcc List based on given type.</param>
        /// <param name="attachments"></param>
        /// <param name="type">cc emails addresses as csv. Will be added to the To,CC, or Bcc List based on given type.</param>
        /// <param name="searchForComma">Checks for comma in the emails and split it if possible.</param>
        /// <param name="isHtml"></param>
        /// <exception cref="Exception">
        ///     If mailer is not configured properly then : "Mailer is not configured correctly. Please
        ///     check credentials , host config and mailing address maybe empty or not declared."
        /// </exception>
        public MailMessage GetMailMessage(
            string mailingTos,
            string subject,
            string body,
            string ccMails,
            List <Attachment> attachments = null,
            MailingType type    = MailingType.RegularMail,
            bool searchForComma = true,
            bool isHtml         = true)
        {
            var sendingToEmails = GetEmailAddressList(mailingTos, searchForComma);
            var ccToEmails      = GetEmailAddressList(ccMails, searchForComma);

            return(GetMailMessage(sendingToEmails, subject, body, ccToEmails, attachments, type, searchForComma, isHtml));
        }
コード例 #7
0
        /// <summary>
        ///     Get a mail message instead of sending the direct email.
        /// </summary>
        /// <param name="mailingTos">Csv email address</param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="ccMails">cc email addresses as csv. Will be added to the To,CC, or Bcc List based on given type.</param>
        /// <param name="type">cc emails addresses as csv. Will be added to the To,CC, or Bcc List based on given type.</param>
        /// <param name="attachments"></param>
        /// <param name="searchForComma">Checks for comma in the emails and split it if possible.</param>
        /// <param name="isHtml"></param>
        /// <exception cref="Exception">
        ///     If mailer is not configured properly then : "Mailer is not configured correctly. Please
        ///     check credentials , host config and mailing address maybe empty or not declared."
        /// </exception>
        public MailSendingWrapper GetMailSendingWrapper(
            string[] mailingTos,
            string subject,
            string body,
            string[] ccMails,
            List <Attachment> attachments = null,
            MailingType type    = MailingType.RegularMail,
            bool searchForComma = true,
            bool isHtml         = true)
        {
            var mail   = GetMailMessage(mailingTos, subject, body, ccMails, attachments, type, searchForComma, isHtml);
            var server = CloneSmtpClient();

            return(new MailSendingWrapper(server, mail));
        }
コード例 #8
0
        /// <summary>
        ///     Send emailAddress with attachments
        /// </summary>
        /// <param name="mailingTos">Csv email address</param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="attachments"></param>
        /// <param name="type"></param>
        /// <param name="searchCommas"></param>
        /// <param name="isAsync"></param>
        /// <param name="isHtml"></param>
        /// <param name="userToken"></param>
        /// <param name="sendCompletedEventHandler"></param>
        /// <exception cref="Exception"></exception>
        public void SendWithAttachments(
            string mailingTos,
            string subject,
            string body,
            List <Attachment> attachments = null,
            MailingType type  = MailingType.RegularMail,
            bool searchCommas = true,
            bool isAsync      = true,
            bool isHtml       = true,
            object userToken  = null,
            SendCompletedEventHandler sendCompletedEventHandler = null)
        {
            var sendingToEmails = GetEmailAddressList(mailingTos, searchCommas);

            SendWithAttachments(sendingToEmails, subject, body, null, attachments, type, isAsync, isHtml, searchCommas, userToken, sendCompletedEventHandler);
        }
コード例 #9
0
        /// <summary>
        ///     Send emailAddress with attachments
        /// </summary>
        /// <param name="mailingTos">Emails will always be added in the To list.</param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="ccMails">ccMails will be added to the To,CC, or Bcc list based on the selected type.</param>
        /// <param name="type">Based on selected type ccMails will be added to the To,CC, or Bcc list.</param>
        /// <param name="isAsync"></param>
        /// <param name="attachments"></param>
        /// <param name="isHtml">Is the body is Html or only text.</param>
        /// <param name="searchForComma">Checks for comma in the emails and split it if possible.</param>
        /// <param name="userToken"></param>
        /// <param name="sendCompletedEventHandler"></param>
        /// <exception cref="Exception"></exception>
        public void SendWithAttachments(
            string[] mailingTos,
            string subject,
            string body,
            string[] ccMails,
            List <Attachment> attachments = null,
            MailingType type    = MailingType.RegularMail,
            bool isAsync        = true,
            bool isHtml         = true,
            bool searchForComma = false,
            object userToken    = null,
            SendCompletedEventHandler sendCompletedEventHandler = null)
        {
            var mailSendingWrapper = GetMailSendingWrapper(mailingTos, subject, body, ccMails, attachments, type, searchForComma, isHtml);

            SendMail(mailSendingWrapper, isAsync);
            //Dispose(mailSendingWrapper);
        }
コード例 #10
0
        private void MailingAddressAttach(ref MailMessage mail, string mailTo, MailingType type)
        {
            mail.To.Clear();

            if (type == MailingType.RegularMail) {
                mail.To.Add(new MailAddress(mailTo));
            } else if (type == MailingType.CarbonCopy) {
                mail.CC.Add(new MailAddress(mailTo));
            } else {
                mail.Bcc.Add(new MailAddress(mailTo));
            }
        }
コード例 #11
0
 /// <summary>
 /// </summary>
 /// <param name="to"></param>
 /// <param name="subject"></param>
 /// <param name="body"></param>
 /// <param name="fileName"></param>
 /// <param name="type"></param>
 /// <param name="searchForCommas"></param>
 /// <exception cref="Exception"></exception>
 public void SendMailWithAttachments(string to, string subject, string body, string fileName,
     MailingType type = MailingType.RegularMail, bool searchForCommas = false)
 {
     if (IsConfigured && !to.IsEmpty()) {
         var t = new Thread(() => {
             var mail = MailSetup(SenderEmail, to);
             MailingAddressAttach(ref mail, to, type, searchForCommas);
             mail.Subject = subject;
             mail.Body = body;
             try {
                 var messageAttachment = new Attachment(fileName);
                 mail.Attachments.Add(messageAttachment);
                 var mailer = CopySmtpClient();
                 if (SendAsynchronousEmails) {
                     new Thread(() => mailer.Send(mail)).Start();
                 } else {
                     mailer.Send(mail);
                 }
             } catch (Exception ex) {
                 Console.WriteLine("Mail Sending Error: " + ex.Message);
                 throw ex;
             }
         });
         t.Start();
     } else {
         throw new Exception(
             "Mailer is not configured correctly. Please check credentials , host config and mailing address maybe empty or not declared.");
     }
 }
コード例 #12
0
        /// <summary>
        ///     Sends mail asynchronously.
        /// </summary>
        /// <param name="to">Comma to seperate multiple email addresses.</param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        /// <param name="from"></param>
        /// <param name="password"></param>
        /// <param name="type">Regular, CC, BCC</param>
        public void QuickSend(string to, string subject, string body, string from, string password,
            MailingType type = MailingType.RegularMail)
        {
            var emailBack = SenderEmail;
            var passwordBack = SenderEmailPassword;

            SenderEmail = from;
            SenderEmailPassword = password;
            SetupCredentials();
            QuickSend(to, subject, body);

            SenderEmail = emailBack;
            SenderEmailPassword = passwordBack;
            SetupCredentials();
        }
コード例 #13
0
 /// <summary>
 ///     Quickly send an email.
 /// </summary>
 /// <param name="to"></param>
 /// <param name="carbonCopyEmails"></param>
 /// <param name="subject"></param>
 /// <param name="body"></param>
 /// <param name="type"></param>
 /// <exception cref="Exception"></exception>
 public void QuickSend(string to, string[] carbonCopyEmails, string subject, string body,
     MailingType type = MailingType.CarbonCopy)
 {
     if (IsConfigured && !to.IsEmpty()) {
         var t = new Thread(() => {
             var mail = MailSetup(SenderEmail, to);
             MailingAddressAttach(ref mail, to, carbonCopyEmails, type);
             mail.Subject = subject;
             mail.Body = body;
             try {
                 var mailer = CopySmtpClient();
                 if (SendAsynchronousEmails) {
                     mailer.SendAsync(mail, "none");
                 } else {
                     mailer.Send(mail);
                 }
             } catch (Exception ex) {
                 Console.WriteLine("Mail Sending Error: " + ex.Message);
                 throw ex;
             }
         });
         t.Start();
     } else {
         throw new Exception(
             "Mailer is not configured correctly. Please check credentials , host config and mailing address maybe empty or not declared.");
     }
 }
コード例 #14
0
 /// <summary>
 /// Add new emails with referenced MailMessage.
 /// </summary>
 /// <param name="mail">MailMessage object to attach the email address to it.</param>
 /// <param name="mailTos">Expecting at least one email address in the array. On null throw exception.</param>
 /// <param name="mailCc">
 ///     If null then no action or else add to the cc list. Based on type of emails will be added to the To,CC, or BCC list.
 /// </param>
 /// <param name="type">Based on type of emails will be added to the To,CC, or BCC list.</param>
 public void MailingAddressAttach(ref MailMessage mail, string[] mailTos, string[] mailCc, MailingType type)
 {
     foreach (var mailTo in mailTos)
     {
         var mailAddress = new MailAddress(mailTo);
         mail.ReplyToList.Add(mailAddress);
         mail.To.Add(mailAddress);
     }
     if (mailCc == null)
     {
         return;
     }
     foreach (var address in mailCc)
     {
         if (type == MailingType.RegularMail)
         {
             mail.To.Add(new MailAddress(address));
         }
         else if (type == MailingType.CarbonCopy)
         {
             mail.CC.Add(new MailAddress(address));
         }
         else
         {
             mail.Bcc.Add(new MailAddress(address));
         }
     }
 }
コード例 #15
0
    public static string[] GetMailingList(MailingType Type)
    {
        /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
        *  Procedure Name : MatrimonialMailList_GetList
        * * * * * * * * * * * * * * * * * * * * * * * * * * * *
        *  Type: SELECT
        * * * * * * * * * * * * * * * * * * * * * * * * * * * *
        *  Parameters :
        * * * * * * * * * * * * * * * * * * * * * * * * * * * *
        *            @Flag tinyint
        * * * * * * * * * * * * * * * * * * * * * * * * * * * *
        *            MailList
        * * * * * * * * * * * * * * * * * * * * * * * * * * * */

        DataSet objDataSet = new DataSet();

        using (SqlConnection objConnection = DBConnection.GetSqlConnection())
        {
            try
            {
                //Creating Command object
                SqlCommand objCommand = new SqlCommand("MatrimonialMailList_GetList", objConnection);
                objCommand.CommandType = CommandType.StoredProcedure;
                //Adding Parameters

                objCommand.Parameters.Add(new SqlParameter("@Flag", SqlDbType.TinyInt));
                switch (Type)
                {
                case MailingType.Newstetter:
                    objCommand.Parameters["@Flag"].Value = 1;
                    break;

                case MailingType.NewProduct:
                    objCommand.Parameters["@Flag"].Value = 2;
                    break;

                case MailingType.ToAll:
                    objCommand.Parameters["@Flag"].Value = 3;
                    break;

                case MailingType.TOPaidMembers:
                    objCommand.Parameters["@Flag"].Value = 4;
                    break;

                case MailingType.TOActiveMembers:
                    objCommand.Parameters["@Flag"].Value = 5;
                    break;

                case MailingType.ToInActiveMembers:
                    objCommand.Parameters["@Flag"].Value = 6;
                    break;

                default:
                    throw new Exception("Wrong Parameter");
                    break;
                }


                objConnection.Open();
                SqlDataAdapter objDataAdapter = new SqlDataAdapter(objCommand);

                objDataAdapter.Fill(objDataSet, "MailList");
                objDataAdapter.Dispose();
            }
            catch (Exception) { }
            finally
            {
                objConnection.Close();
            }

            if ((objDataSet.Tables["MailList"].Rows.Count != null) && (objDataSet.Tables["MailList"].Rows.Count > 0))
            {
                string[] strAList       = new string[objDataSet.Tables["MailList"].Rows.Count];
                int      intIncreminent = 0;
                if ((Type == MailingType.ToInActiveMembers) || (Type == MailingType.TOPaidMembers) || (Type == MailingType.TOActiveMembers))
                {
                    foreach (DataRow objDataRow in objDataSet.Tables["MailList"].Rows)
                    {
                        strAList[intIncreminent] = Crypto.DeCrypto(objDataRow["MailAddress"].ToString());
                        ++intIncreminent;
                    }
                }
                else
                {
                    foreach (DataRow objDataRow in objDataSet.Tables["MailList"].Rows)
                    {
                        strAList[intIncreminent] = objDataRow["MailAddress"].ToString();
                        ++intIncreminent;
                    }
                }
                return(strAList);
            }
            else
            {
                return(null);
            }
        }
    }
コード例 #16
0
 private void MailingAddressAttach(ref MailMessage mail, string mailTo, MailingType type, bool searchForComma)
 {
     mail.To.Clear();
     if (searchForComma && mailTo.IndexOf(",") > -1) {
         var mailingAddresses = mailTo.Split(',').ToArray();
         foreach (var address in mailingAddresses) {
             if (type == MailingType.RegularMail) {
                 mail.To.Add(new MailAddress(address));
             } else if (type == MailingType.CarbonCopy) {
                 mail.CC.Add(new MailAddress(address));
             } else {
                 mail.Bcc.Add(new MailAddress(address));
             }
         }
     } else {
         if (type == MailingType.RegularMail) {
             mail.To.Add(new MailAddress(mailTo));
         } else if (type == MailingType.CarbonCopy) {
             mail.CC.Add(new MailAddress(mailTo));
         } else {
             mail.Bcc.Add(new MailAddress(mailTo));
         }
     }
 }
コード例 #17
0
 /// <summary>
 /// Add a single parameter to the query
 /// </summary>
 /// <param name="name">the name of the parameter</param>
 /// <param name="value">the value of the parameter</param>
 /// <returns>this query</returns>
 public QueryParameters Add(string name, MailingType value)
 {
     this.Add(new KeyValuePair <string, string>(name, MaileonEnums.ToXmlString(value)));
     return(this);
 }
コード例 #18
0
        private void MailingAddressAttach(ref MailMessage mail, string mailTo, string[] mailCc, MailingType type)
        {
            mail.To.Clear();
            mail.To.Add(new MailAddress(mailTo));

            foreach (var address in mailCc) {
                if (type == MailingType.RegularMail) {
                    mail.To.Add(new MailAddress(address));
                } else if (type == MailingType.CarbonCopy) {
                    mail.CC.Add(new MailAddress(address));
                } else {
                    mail.Bcc.Add(new MailAddress(address));
                }
            }
        }
コード例 #19
0
        /// <summary>
        /// Create a mailing
        /// </summary>
        /// <param name="userKey">User Key of the user who initiates the call.</param>
        /// <param name="name">Name of the mailing.</param>
        /// <param name="campaignId">ID of the campaign you want to associate the mailing with.</param>
        /// <param name="type">Type of the mailing. Possible values: 'standard', 'recurring', 'absplit'</param>
        /// <param name="recurringId">ID of the first recurrence in case of a 'recurring' or 'absplit' mailing.</param>
        /// <param name="encoding">Encoding to be used for the mailing. Possible values: 'utf-8', 'iso-8859-x'</param>
        /// <param name="transferEncoding">Transfer encoding to be used for the mailing. Possible values: 'quoted-printable', 'base64'</param>
        /// <param name="clientId">Client ID of the client in which the mailing is created.</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>ID of the new mailing</returns>
        public Task <long> CreateAsync(string userKey, string name, long?campaignId = null, MailingType type = MailingType.Standard, long?recurringId = null, MessageEncoding?encoding = null, TransferEncoding?transferEncoding = null, long?clientId = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var parameters = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>("user_key", userKey),
                new KeyValuePair <string, object>("name", name),
                new KeyValuePair <string, object>("type", type.GetEnumMemberValue())
            };

            if (campaignId.HasValue)
            {
                parameters.Add(new KeyValuePair <string, object>("campaign_id", campaignId.Value));
            }
            if (recurringId.HasValue)
            {
                parameters.Add(new KeyValuePair <string, object>("recurring_id", recurringId.Value));
            }
            if (encoding.HasValue)
            {
                parameters.Add(new KeyValuePair <string, object>("encoding", encoding.Value.GetEnumMemberValue()));
            }
            if (transferEncoding.HasValue)
            {
                parameters.Add(new KeyValuePair <string, object>("transfer_encoding", transferEncoding.Value.GetEnumMemberValue()));
            }
            if (clientId.HasValue)
            {
                parameters.Add(new KeyValuePair <string, object>("client_id", clientId.Value));
            }

            return(_client
                   .PostAsync("Mailing/Create")
                   .WithFormUrlEncodedBody(parameters)
                   .WithCancellationToken(cancellationToken)
                   .AsCakeMailObject <long>());
        }