shawnmclean / Mandrill-dotnet

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

Mandrill.EmailMessage Attachments property not available #75

Open DEWaller opened 10 years ago

DEWaller commented 10 years ago

When attempting to add a IENumerable list of attachments the property is not available and neither is it possible to declare Mandrill.Attachment.

capture

version 1.0.85

mhallin79 commented 10 years ago

Hi David,

Apologies for not responding with VB code but the below works in C#,

            var imageBytes = File.ReadAllBytes(@"C:\temp\Mandrill.png");
            var pdfBytes = File.ReadAllBytes(@"C:\temp\mandrill.pdf");

            var attachments = new[]
                              {
                                  new attachment
                                  {
                                      content = Convert.ToBase64String(imageBytes),
                                      name = "Mandrill.png",
                                      type = "image/png"
                                  },
                                  new attachment
                                  {
                                      content = Convert.ToBase64String(pdfBytes),
                                      name = "Mandrill.pdf",
                                      type = "application/pdf"
                                  }
                              };

            var to = new []
                     {
                         new EmailAddress("to@domain.com", "John Doe To"),
                         new EmailAddress("ccdomain.com", "John Doe CC", "cc")
                     };

            const string text = "Mandrill attachements.";

            var emailMessage = new EmailMessage
            {
                from_email = "from@domain.com",
                from_name = "John Doe",
                subject = text,
                html = string.Format("<body><p>{0}</p></body>", text),
                text = text,
                subaccount = "1",
                preserve_recipients = true,
                attachments = attachments,
                to = to
            };

            var api = new MandrillApi(ApiKey);
            var response = api.SendMessage(emailMessage);

I hope it helps,

Cheers!

Mikael

DEWaller commented 10 years ago

Mikael,

Thank you so much for your input.

I had already tried this solution, or something very similar, and it was not possible to create the type Mandrill.Attachment (hence the reference to Nothing in my screenshot) as a single entity or part of a list of entities.

The Intellisense dialogue error gives the following.

“attachments is ambiguous because multiple kinds of members with this name exist in the class ‘Mandrill.EmailMessage’”

Examining the source code I can only find one instance of ‘attachment’ so the error remains elusive.

Neither Attachment or Attachments are being exposed for some reason.

Best regards,

David

From: Mikael Hallin [mailto:notifications@github.com] Sent: 21 July 2014 05:50 To: shawnmclean/Mandrill-dotnet Cc: David Waller Subject: Re: [Mandrill-dotnet] Mandrill.EmailMessage Attachments property not available (#75)

Hi David,

Apologies for not responding with VB code but the below works in C#,

        var imageBytes = File.ReadAllBytes(@"C:\temp\Mandrill.png");
        var pdfBytes = File.ReadAllBytes(@"C:\temp\mandrill.pdf");

        var attachments = new[]
                          {
                              new attachment
                              {
                                  content = Convert.ToBase64String(imageBytes),
                                  name = "Mandrill.png",
                                  type = "image/png"
                              },
                              new attachment
                              {
                                  content = Convert.ToBase64String(pdfBytes),
                                  name = "Mandrill.pdf",
                                  type = "application/pdf"
                              }
                          };

        var to = new []
                 {
                     new EmailAddress("to@domain.com", "John Doe To"),
                     new EmailAddress("ccdomain.com", "John Doe CC", "cc")
                 };

        const string text = "Mandrill attachements.";

        var emailMessage = new EmailMessage
        {
            from_email = "from@domain.com",
            from_name = "John Doe",
            subject = text,
            html = string.Format("<body><p>{0}</p></body>", text),
            text = text,
            subaccount = "1",
            preserve_recipients = true,
            attachments = attachments,
            to = to
        };

        var api = new MandrillApi(ApiKey);
        var response = api.SendMessage(emailMessage);

I hope it helps,

Cheers!

Mikael

— Reply to this email directly or view it on GitHub https://github.com/shawnmclean/Mandrill-dotnet/issues/75#issuecomment-49571769 .

mhallin79 commented 10 years ago

Hi David,

Unfortunately I'm not familiar enough with VB to help you out but I have verified that the code snippet above works in version 1.0.85.

Sorry,

Mikael

DEWaller commented 10 years ago

Hi Mikail,

I can confirm the code snippet works in a C# VS project even though ‘attachments’ is not a listed property of EmailMessage…

mandrill_1

the code compiles and runs without error.

However, in a VB project the code will not compile because the ‘attachments’ property is not recognised.

mandrill_2

I hope this helps.

David

From: Mikael Hallin [mailto:notifications@github.com] Sent: 21 July 2014 06:22 To: shawnmclean/Mandrill-dotnet Cc: David Waller Subject: Re: [Mandrill-dotnet] Mandrill.EmailMessage Attachments property not available (#75)

Hi David,

Unfortunately I'm not familiar enough with VB to help you out but I have verified that the code snippet above works in version 1.0.85.

Sorry,

Mikael

— Reply to this email directly or view it on GitHub https://github.com/shawnmclean/Mandrill-dotnet/issues/75#issuecomment-49572611 .

DEWaller commented 10 years ago

Delving deeper into the code the problem arises due to the existence of Mandrill.Attachment (class) and Mandrill.attachment (structure). As C# is case sensitive then ambiguity is avoided. However VB is not case sensitive resulting in ambiguity.

waol commented 10 years ago

Solution = Making the assembly CLS-compliant

JasonElkin commented 10 years ago

@waol @vegplot it's easy enough to fix if you just refactor that struct, as I have.

Fixing it for VB will introduce a breaking change... but I've made a pull request anyway, it would be better if it was CLS compliant.

waol commented 10 years ago

OK, thank you. I have already fixed it, but I think also that it would be better if the library was CLS compliant.

From: JasonElkin [mailto:notifications@github.com] Sent: lundi 4 août 2014 11:38 To: shawnmclean/Mandrill-dotnet Cc: Wao. Olivier Wallemacq Subject: Re: [Mandrill-dotnet] Mandrill.EmailMessage Attachments property not available (#75)

@waolhttps://github.com/waol @vegplothttps://github.com/vegplot it's easy enough to fix if you just refactor that struct, as I havehttps://github.com/JasonElkin/Mandrill-dotnet.

Fixing it for VB will introduce a breaking change... but I've made a pull request anyway, it would be better if it was CLS compliant.

— Reply to this email directly or view it on GitHubhttps://github.com/shawnmclean/Mandrill-dotnet/issues/75#issuecomment-51037008.

preguntoncojonero commented 9 years ago

Maybe can be include in Integration tests.

Those Tests would be very interesting:

Send message with attachment files (images, pdf, ...)

Send message with inline images

Send message with inline images using template