tags:

views:

22

answers:

2

I have the following code which attaches an image to the email but I need this image to be embedded in the html of the email.

Any ideas??

objMM.Attachments.Add(new MailAttachment(Server.MapPath("images1/links/beach-icon.jpg")))

  objMM.Body = "<p>There should be an attachment</p> <img src='beach-icon.jpg' /> <p>with this email</p>"
A: 

try this code

 public static bool SendBulkEmailWithAttachment(String fromEmail, String toEmail, String subject, String body)


 {
       MailMessage objMail = new MailMessage();

       objMail.To.Add(toEmail);
       objMail.From = new MailAddress(fromEmail);

       try
       {
           objMail.IsBodyHtml = true;
           objMail.Subject = subject;
           objMail.Body = body;

               System.IO.Stream inputStream = //Image path;
               String fileName = "FileName";
               Attachment attach = new Attachment(inputStream, fileName);

               objMail.Attachments.Add(attach);


           SmtpClient SmtpClnt = new SmtpClient();
           SmtpClnt.Send(objMail);
           return true;
       }
       catch (Exception ex)
       {
           throw ex;
       }
   }
Muhammad Akhtar
A: 

I think this does the job, though it doesn't work in Mail for Mac OSX

Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString("This is my plain text content, viewable by those clients that don't support html", Nothing, "text/plain")

Dim logo As New LinkedResource(Server.MapPath("images1/links/beach-icon.jpg"))

logo.ContentId = "embeddedimage"

Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString("<p>Here is an embedded image.</p> <img src=cid:embeddedimage> <p>More text here</p>", Nothing, "text/html")

htmlView.LinkedResources.Add(logo)

objMM.AlternateViews.Add(plainView)
objMM.AlternateViews.Add(htmlView)
Tom