shawnmclean / Mandrill-dotnet

.NET wrapper for Mandrill
Other
202 stars 107 forks source link

cc not working #190

Open Morgs007 opened 7 years ago

Morgs007 commented 7 years ago

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( "email2@gmail.com", "Receiver Name 1", "to" ) );
to.Add( new EmailInfo( "email1@gmail.com", "Receiver Name 2", "cc" ) );
shawnmclean commented 7 years ago

What part of the API are you using?

Morgs007 commented 7 years ago

See attached capture

shawnmclean commented 7 years ago

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

Morgs007 commented 7 years ago

Ohk sorry here's my implementation:

  1. Email

    /// <summary>
        /// Helper function to create an email message
        /// </summary>
        /// <param name="to"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        private EmailMessage BuildEmailMessage( IEnumerable<EmailInfo> to, EmailMessageModel model )
        {
            List<EmailAddress> recipients = new List<EmailAddress>() { };
    
            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 commented 6 years ago

@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 commented 6 years ago

This will be fixed by https://github.com/shawnmclean/Mandrill-dotnet/pull/203 when approved/merged

Morgs007 commented 6 years ago

Thank you guys this has actually been an issue until now. I will implement and revert

On Thu, 24 May 2018 at 19:53, William Daniels notifications@github.com wrote:

This will be fixed by #203 https://github.com/shawnmclean/Mandrill-dotnet/pull/203 when approved/merged

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/shawnmclean/Mandrill-dotnet/issues/190#issuecomment-391803540, or mute the thread https://github.com/notifications/unsubscribe-auth/AYO5MJ6fE9v07kz3zpU8URAAzO-Sfl2Qks5t1vOAgaJpZM4OUu5h .