none
How to batch emails with data as BCC RRS feed

  • Question

  • Hello,

    I have the batch email working...after a fashion. I can batch emails as long as I don't incorporate any data into it.

    // Create three separate email messages.
               EmailMessage message1 = new EmailMessage(ExService);
               message1.Subject = "this is my subject";
               message1.Body = customerRequest;
               message1.ToRecipients.Add(primaryTo);  // Note that we are only sending to the primaryTo address for the first batch, not every one
                // Loop through the members affected
                     foreach (var email in getList){
                         sCount++;
                         if (sCount <= 50) {      
                                 // Add each member to this email
                                  message1.BccRecipients.Add(email.Email); //gather the emails in each batch.  
                                  }
                          } 

    Does anyone know how I could do this?

    Thanks

    Wednesday, April 29, 2015 3:03 PM

All replies

  • Your question isn't very clear can you rephrase what your asking, if you are getting an error its better to post the details of the error you receive.

    Exchange has recipient limits so there will be a limit to the number of people you can BCC on a message https://technet.microsoft.com/en-us/library/bb124405.aspx

    Cheers
    Glen

    Thursday, April 30, 2015 1:52 AM
  • I can batch emails if I hard code the:

     message1.BccRecipients.Add("lmayer@myemail.com");

    However if I try to add emails from a database it doesn't work:

     foreach (var email in getList){
                         sCount++;
                         if (sCount <= 50) {      
                                 // Add each member to this email
                                  message1.BccRecipients.Add(email.Email); //gather the emails in each batch.  
                                  }
                          } 

    How can I add the emails and data to the body from a database and batch up the emails using this code:

    https://msdn.microsoft.com/en-us/library/office/dn595098%28v=exchg.150%29.aspx?f=255&MSPPError=-2147217396#bk_createewsma



    • Edited by Inverarry Thursday, April 30, 2015 12:16 PM
    Thursday, April 30, 2015 12:14 PM
  • >>However if I try to add emails from a database it doesn't work:

     How doesn't it work ? what error do you receive ?

      All I can see that your doing is that your adding BCC recipients so the method your using

      BccRecipients.Add

     Expects you to pass a String

     From

    message1.BccRecipients.Add(email.Email);

     Is the .Email property a String ?

     You can add a body to the Message using the Body property eg

     
    email.Subject = "HelloWorld";
    email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API.");
    Cheers
    Glen

    Friday, May 1, 2015 4:39 AM
  • I'm sorry I thought I was clear. A foreach loops through a query and passes the data as a variable in this case email.email which would equal lmayer@mywork.com, lmayer1@mywork.com ect until the foreach loops through all the records. The BccRecipients.Add(email.Email); accomplishes that.

    My problem is that after 10 minutes it still does not complete and nothing happens. When I hard code the email instead it works fine. There must be a way to loop through emails or what would be the point?

    Laura


    • Edited by Inverarry Friday, May 1, 2015 12:06 PM
    Friday, May 1, 2015 12:06 PM
  • It sounds like you have an infinate loop, your exceeding a limit or probably more likely because your feeding in values from a database one of the database values is invalid. The only thing you can do is a line by line debug of your code in Visual studio to work out which line of code is casuing the problem. Also if your batching reduce the size of the batch. I would suggest you enable tracing https://msdn.microsoft.com/en-us/library/office/dd633676%28v=exchg.80%29.aspx which will let you see what is being submitted to the server (if it is getting that far) you can also look at the EWS Logs on the CAS server. The trace logs will generally be the most use.

    Cheers
    Glen

    Friday, May 1, 2015 11:16 PM