0

I am attempting to attach image files to emails sent by my website.

I have followed the method used here

http://www.aspnettutorials.com/tutorials/email/email-with-img-asp4-cs/

This is the code I have written

    string smtpServer = "my server";

    SmtpClient client = new SmtpClient(smtpServer);

    MailMessage message = new MailMessage();

    string img = "/img/emails/test.png";


    Attachment imgAtt = new Attachment(HttpContext.Current.Server.MapPath(img));

    imgAtt.ContentId = Path.GetFileName(img);
    //add the attachment to the email
    message.Attachments.Add(imgAtt);

    message.From = new MailAddress("example@example.com");
    message.To.Add(new MailAddress("otherexample@example.com"));
    message.Subject = "test";
    message.Body = "<img src=\"cid:test.png\">";
    message.IsBodyHtml = true;

    client.Send(message);

This is working fine accept when the person receiving the email uses Mac Mail. In this case the image is displayed twice when the person views the email. Is there a solution to this problem?

Edit: I have tried the solution on sending mail along with embedded image using asp.net. However I have had the same outcome. Users with mac mail still see the image twice.

Community
  • 1
  • 1
Dave Barnett
  • 2,045
  • 2
  • 16
  • 32
  • 1
    You want to attach images.. this is a simple attachment.. why are you then trying to embed that in the body? You either attach, or use an alternate view to embed. Not both. – Abhitalks Nov 11 '14 at 13:04
  • This is just test code. On my website I need to send an email that has images that are positioned using html. Hence simply attaching is not enough. – Dave Barnett Nov 11 '14 at 13:29
  • I'll give that a try. Thanks very much. I think you're right about it being a dupe. My search strategy obviously needs to be improved! – Dave Barnett Nov 11 '14 at 16:11

0 Answers0