Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cc not working #190

Open
Morgs007 opened this issue Jul 11, 2017 · 7 comments
Open

cc not working #190

Morgs007 opened this issue Jul 11, 2017 · 7 comments

Comments

@Morgs007
Copy link

The 'cc' is not working. Whenever I add a 'to' and a 'cc', it sends 2 separate email instead of cc'ing the 2nd recipient. Anyway around this? Just recently updated the dll using Visual Studio Nuget and that didn't help...:


List<EmailInfo> to = new List<EmailInfo>();
to.Add( new EmailInfo( "[email protected]", "Receiver Name 1", "to" ) );
to.Add( new EmailInfo( "[email protected]", "Receiver Name 2", "cc" ) );
@shawnmclean
Copy link
Owner

What part of the API are you using?

@Morgs007
Copy link
Author

See attached
capture

@shawnmclean
Copy link
Owner

Sorry, I meant what API call are you using? What class is that EmailInfo?

@Morgs007
Copy link
Author

Morgs007 commented Jul 24, 2017

Ohk sorry here's my implementation:

  1. Email
    ```
    ///


    /// Helper function to create an email message
    ///

    ///
    ///
    ///
    private EmailMessage BuildEmailMessage( IEnumerable to, EmailMessageModel model )
    {
    List recipients = new List() { };

         foreach ( var info in to )
         {
             recipients.Add( new EmailAddress()
             {
                 Email = info.Email,
                 Name = info.Name,
                 Type = info.Type
             } );
         }
    
         EmailMessage message = new EmailMessage()
         {
             FromEmail = model.FromEmail,
             FromName = model.FromName,
             Subject = model.Subject,
             To = recipients,
             Html = model.Html
         };
    
         if ( model.Attachments != null && model.Attachments.Any() )
         {
             message.Attachments = BuildEmailAttachment( model.Attachments );
         }
    
         return message;
     }
    
Note: The `recipients.Add( new EmailMessage() )` specifies the Type, this type was set as per my initial post as "to" and "cc".

2. Send:
         ```
/// <summary>
        /// Sends an email message using the specified template.
        /// </summary>
        /// <param name="to"></param>
        /// <param name="model"></param>
        /// <param name="template"></param>
        /// <returns></returns>
        public async Task SendTemplateAsync( IEnumerable<EmailInfo> to, EmailMessageModel model, string template )
        {
            MandrillApi api = new MandrillApi( _apiKey );
            EmailMessage message = BuildEmailMessage( to, model );
            SendMessageTemplateRequest request = new SendMessageTemplateRequest( message, template );
            List<EmailResult> result = await api.SendMessageTemplate( request );
        }

@WillBDaniels
Copy link
Contributor

@Morgs007 to fix this, please just add 'PreserveRecipients = true' to your emailMessage, which will then cause mandrill (downstream) to respect the cc/bcc emails and not split them apart. This is due to a bug in this SDK, which I will open a PR for shortly.

Good luck!

@WillBDaniels
Copy link
Contributor

This will be fixed by #203 when approved/merged

@Morgs007
Copy link
Author

Morgs007 commented May 24, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants