1

I am trying to send an email from an iOS device (Using Xamarin) in an HTML format with images embedded in the body of the email.

Some solutions that I found online suggest to use an approach similar to the one shown here:

NSData ImgData = UIImage.FromFile(FileName).AsJPEG();
string img64baseStr = ImgData.GetBase64EncodedString(NSDataBase64EncodingOptions.None);
string srcStr = string.Format("data:image/jpg;base64,{0}", img64baseStr);

Using the code above I can see the pictures properly in the iOS Email client. However, when the email is sent I can't see the images on the receiving side. There are other setbacks to this approach, but I can avoid getting into those in more details at this point.

I have also tried using the images as resources in the project. However, when I reference the pictures directly in the HTML in this form:

<img src="Pic1.png" width="700" height="500" alt=""/>

the linkage is broken and the email is missing the images.

How can I properly reference resource images in an HTML email?

Jay M
  • 979
  • 1
  • 12
  • 23
  • 1
    You should share some code so we might see what's wrong with your implementation. After all, there are multiple ways to send emails. – Timo Salomäki Feb 15 '17 at 18:33
  • 2
    Possible duplicate of [How to embed an image in the HTML body of an email in iOS](http://stackoverflow.com/questions/10397775/how-to-embed-an-image-in-the-html-body-of-an-email-in-ios) – SushiHangover Feb 15 '17 at 18:33
  • 2
    @SushiHangover possible dupe, but there are no Xamarin examples or answers in that question. – JAL Feb 15 '17 at 18:35
  • 1
    @SushiHangover, Thanks. The link you sent is in Objective-C. I am looking for a xamarin solution. – Jay M Feb 15 '17 at 18:38
  • @JAL Easy enough to convert a few lines of code between languages... – SushiHangover Feb 15 '17 at 18:38
  • 2
    @JayJacobs Show what you have tried in C# and what is not actually working... – SushiHangover Feb 15 '17 at 18:39

1 Answers1

1

So it seems like the approach described above, of converting the data object to a base64 string is deprecated by most email clients for security reasons and the email client will block Dada URIs that are arriving this way.

I found the question posted in the link below to be helpful for understanding why things weren't working for me:

base64 encoded images in email signatures

Specifically refer to the answer posted by @Shadow2531 and the discussion that followed it.

Finally, I was able to achieve what I wanted using the MailKit package that is available on NuGet. The package has a pretty comprehensive documentation. Specifically for the problem I was trying to solve, take a look at this page:

http://www.mimekit.net/docs/html/CreatingMessages.htm

Good luck.

Community
  • 1
  • 1
Jay M
  • 979
  • 1
  • 12
  • 23