none
Emailing inline jpg image comes as ATT00001.bin on MAC Outlook RRS feed

  • Question

  • I am using AlternateView with a LinkedResource for an image.

    Something like this:

    AlternateView avBody = AlternateView.CreateAlternateViewFromString(text, null, "text/<g class="gr_ gr_92 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling" data-gr-id="92" id="92">html</g>");

                ImagePath = Environment.CurrentDirectory + ImagePath;
                if (File.Exists(ImagePath))
                {
                    LinkedResource ImageHeader = new LinkedResource(ImagePath);
                    ImageHeader.ContentId = "ImageHeader";
                    avBody.LinkedResources.Add(ImageHeader);
                }

    Then I use System.Net.Mail library to send the email through smtp server. The email is sucesfully delivered on PC Outlook or gmail, but on MAC Outlook the image comes as ATT00001.bin attachment. How could this be fixed?

    Thank you in advance!

    Friday, May 4, 2018 5:40 PM

Answers

  • Hello,

    I don't have time to do this in C#, this is code I did back in VS2010 and had done this from noting images where not coming across on iPhones.

    Imports System.Net.Mail
    
    Public Class EmailDemo
        Sub Demo1()
            Dim mail As New MailMessage()
            mail.From = New MailAddress("xxxxxxxxx@comcast.net")
            mail.To.Add("xxxxxx@gmail.com")
            mail.Subject = "This is an email"
            Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString(
                "This is my plain text content, viewable by those clients that don't support html", Nothing, "text/plain")
            'then we create the Html part
            'to embed images, we need to use the prefix 'cid' in the img src value
            'the cid value will map to the Content-Id of a Linked resource.
            'thus <img src='cid:companylogo'> will map to a LinkedResource with a ContentId of 'companylogo'
            Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(
                "This is an automated email, please do not respond<br><br>An exception ocurred in <br>" &
                "<span style=""font-weight: bold; padding-left: 20px;padding-right:5px"">" &
                "Application name</span>MyApp<br><span style=""font-weight: bold; padding-left: 5px;" &
                "padding-right:5px"">Application Version</span>1.00<br><span style=""font-weight: bold;" &
                " padding-left: 70px;padding-right:5px""><img src=cid:companylogo>", Nothing, "text/html")
    
            Dim logo As New LinkedResource("C:\Dotnet2010\Work1\SendMessage\bin\Debug\logo.jpg", "image/jpeg")
    
            logo.ContentId = "companylogo"
    
            htmlView.LinkedResources.Add(logo)
            mail.AlternateViews.Add(plainView)
            mail.AlternateViews.Add(htmlView)
    
            Dim smtp As New SmtpClient("smtp.comcast.net")
            smtp.Send(mail)
        End Sub
    End Class
    

    The important parts are highlighted


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by ssbobkova Tuesday, May 8, 2018 12:03 AM
    Friday, May 4, 2018 7:36 PM
    Moderator

All replies

  • Hello,

    I don't have time to do this in C#, this is code I did back in VS2010 and had done this from noting images where not coming across on iPhones.

    Imports System.Net.Mail
    
    Public Class EmailDemo
        Sub Demo1()
            Dim mail As New MailMessage()
            mail.From = New MailAddress("xxxxxxxxx@comcast.net")
            mail.To.Add("xxxxxx@gmail.com")
            mail.Subject = "This is an email"
            Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString(
                "This is my plain text content, viewable by those clients that don't support html", Nothing, "text/plain")
            'then we create the Html part
            'to embed images, we need to use the prefix 'cid' in the img src value
            'the cid value will map to the Content-Id of a Linked resource.
            'thus <img src='cid:companylogo'> will map to a LinkedResource with a ContentId of 'companylogo'
            Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(
                "This is an automated email, please do not respond<br><br>An exception ocurred in <br>" &
                "<span style=""font-weight: bold; padding-left: 20px;padding-right:5px"">" &
                "Application name</span>MyApp<br><span style=""font-weight: bold; padding-left: 5px;" &
                "padding-right:5px"">Application Version</span>1.00<br><span style=""font-weight: bold;" &
                " padding-left: 70px;padding-right:5px""><img src=cid:companylogo>", Nothing, "text/html")
    
            Dim logo As New LinkedResource("C:\Dotnet2010\Work1\SendMessage\bin\Debug\logo.jpg", "image/jpeg")
    
            logo.ContentId = "companylogo"
    
            htmlView.LinkedResources.Add(logo)
            mail.AlternateViews.Add(plainView)
            mail.AlternateViews.Add(htmlView)
    
            Dim smtp As New SmtpClient("smtp.comcast.net")
            smtp.Send(mail)
        End Sub
    End Class
    

    The important parts are highlighted


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by ssbobkova Tuesday, May 8, 2018 12:03 AM
    Friday, May 4, 2018 7:36 PM
    Moderator
  • Thank you! This worked! Turns out I was missing "image/jpeg" when creating new LinkedResource:

    Dim logo As New LinkedResource(ImagePath, "image/jpeg")

    Tuesday, May 8, 2018 12:07 AM