简体   繁体   中英

C# Outlook Mail background Image item, no-repeat is not working in inline

Hi have to run a email campaign where data will go in the mail body along with a background image.

I am passing background image in style of the page and issue is image is getting repeated and when I ma putting background-repeat: no-repeat then image is not getting inline in mail body.

Note - If I add background-repeat:no-repeat; Image wont come at all.. need help.. Oulook2010 Windows10 C#

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using Office = Microsoft.Office.Core;

namespace ConvertFileToHTML
{
    class Outlook4
    {
        private void CreateMailItem(string movieImageName)
        {
            Outlook.Application outlookApp = new Outlook.Application();
            //Outlook.NameSpace outlookNamespace = new Outlook.NameSpace();

            Outlook.MailItem outlookMsg = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
            outlookMsg.Subject = "Selected Movie Tiem Name 6";

            Outlook.Attachment outlookAttachemtn = outlookMsg.Attachments.Add(@"D:\Images\bg1.jpg", Outlook.OlAttachmentType.olEmbeddeditem, null, movieImageName);
            string html_image = movieImageName;

            var schema = "http://schemas.microsoft.com/mapi/proptag/0x3712001E";
            outlookAttachemtn.PropertyAccessor.SetProperty(schema, html_image);


            string html_string;
            html_string = "<html>"+
                "<style type=\"text / css\">h1{color:blue;}"+
               
                "body{background: url(\"cid:bg1.jpg\");}" +
                "</style>" +

                "<body><p>\n" +
                
                "<h1> Name3 </h1></P>" +
                "<h1> Name 3</h1></P>" +
                "<h1> Poster  </h1></P>" +
                "</body></html>";
            //HTML body
            outlookMsg.HTMLBody = html_string;

            Outlook.Recipients olook_reci = (Outlook.Recipients)outlookMsg.Recipients;
            Outlook.Recipient olook_reci_email = (Outlook.Recipient)olook_reci.Add("hkjobs1988@gmail.com");

            olook_reci_email.Resolve();
            outlookMsg.Send();

        }
        static void Main(string[] args)
        {
            Outlook4 pg = new Outlook4();
            pg.CreateMailItem("bg1.jpg");
        }
    }
}

repeated image in outlook mail background post removing no-repeat from style..

在此处输入图像描述

Actual Image --

在此处输入图像描述

Email clients does not support all html and CSS specifications and you must read the support guide for specific client (if you are are sure all your recipients will receive with the same client).

Desktop clients like outlook has more limitations compared to web clients.

so there is not a global solution and this question is not related to C# either. the best way is to test various combinations of possible way with html only mail on your target client and then put it on your C# mail body.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM