我終於找到一個可行的方法:嵌入圖像在電子郵件本身。我找到了解決方案here。以防萬一,我會在這裏包括關鍵的東西。
有三個關鍵組件來電子郵件:純文本版本,HTML版本和圖像,所有consructed爲AlternateViews:
string imagePath = @"C:\Work\images\clickhere.jpg";
AlternateView imageView = new AlternateView(imagePath, MediaTypeNames.Image.Jpeg);
imageView.ContentId = "uniqueId";
imageView.TransferEncoding = TransferEncoding.Base64;
:
//loop to generate the url and send the emails containing
AlternateView plainTextView = AlternateView.CreateAlternateViewFromString(
BuildPlainTextMessage(url), null, "text/plain");
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(
BuildHtmlMessage(url), null, "text/html");
//set up MailAddress objects called to and from
:
MailMessage mail = new MailMessage(from, to);
mail.Subject = "ACTION REQUIRED: Do this by then or else";
mail.AlternateViews.Add(plainTextView);
mail.AlternateViews.Add(htmlView);
mail.AlternateViews.Add(imageView);
//send mail using SmtpClient as normal
:
//endloop
BuildHtmlMessage(串)和BuildPlainTextMessage(串)剛剛返回包含字符串消息。 BuildHtmlMessage包括這個在'url'鏈接中顯示圖像:
sb.AppendLine("<div>");
sb.AppendFormat("<a href=\"{0}\" target=\"_blank\">", url);
sb.Append("<img alt=\"Click here button image\" hspace=0 src=\"cid:uniqueId\" ");
sb.Append("align=baseline border=0 >");
sb.Append("</a>");
sb.AppendLine("</div>");
希望這對其他人有用。
感謝您的答覆。我曾經犯過把圖像放在AuthN網站上的錯誤,但我已經將它移到了另一個只有匿名訪問的網站。不過,我會在Firefox中檢查它。我還試着用標準鏈接的電子郵件 - 我只是直接在電子郵件地址,並允許Notes轉換爲鏈接,它的工作,打開我的機器上的IE瀏覽器。 – serialhobbyist 2010-03-04 08:07:29