Open Morgs007 opened 7 years ago
What part of the API are you using?
See attached
Sorry, I meant what API call are you using? What class is that EmailInfo
?
Ohk sorry here's my implementation:
/// <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".
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 );
}
@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!
This will be fixed by https://github.com/shawnmclean/Mandrill-dotnet/pull/203 when approved/merged
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 .
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...: