0
votes

I'm creating a MailMessage that I'm sending to a SMTP server (via SmtpClient). I've got it to work quite well including the html part (by Adding IsBodyHtml = true to the MailMessage.

I'm currently having quite a few troubles with putting images into the html mail though. I've tried it with an alternateview and also with attachments which somehow didnt work for me.

The last version is now to inlcude the icon from an external source which also does not work and where I'm wondering if that is inherent that it does not work or if I'm doing something wrong there.

The code in the mail (as seen from the smpt server (just the image part):

<img alt="" hspace=0 border=0 align=baseline src="http://MyWebsite.at/Design/favicon.ico">

The command I use to put the image there (I'm replacing a placeholder inside the body):

newMail.Body = newMail.Body.Replace("#MyWebsiteLOGO#", "<img alt=\"\" hspace=0 border=0 align=baseline src=\"http://MyWebsite.at/Design/favicon.ico\">");

Like I said the image part is put into a MailAddress (isBodyHtml = true) and I'm using an SmtpClient to transfer the message.

1
do the clients say something there? or just block because currently I only got an empty image like before and no message from the client? (embedding the picture I'm at step 1 again then :/ got the attachment in both cases but it doesnt want to be used) - Thomas
Small addon there: even if I send the mail to another client and download the external image ..... result is a "nonexistant image" image. - Thomas
Every client may be different. It's also probably that you can't use .ico files in that way. Use .gif or .jpg. - DavidG
From what I saw icons SHOULD be useable (at least there were a few questions even on stackoverflow where they were used as attachments) - Thomas
And can you be sure that every email client can handle icons? - DavidG

1 Answers

0
votes

There's two problems with your code. Firstly most email clients likely cannot handle ico files so it's preferable to stick with known formats like gif and jpg.

Secondly, almost every email client will block external links. You have to embed the image inside the email. You can get round this in 2 ways:

  1. In your c# code add the image as a LinkedResource object and reference it from the HTML as <img src="cid:nameOfImage.gif" />
  2. Convert your image file to base64 and embed it directly in the HTML source. There are various website that will help you do this, for example: http://webcodertools.com/imagetobase64converter/Create