Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Reader,

How we can apply background image for email. I am working with sharepoint and c#.
In the beginning i thought it simple to apply background image as we can send email in HTML format.

But apparently I got to know that Microsoft Office 2003 + does not support background css image which is a setback for my new requirement. ref MSO 07 does not support CSS background[^]

I found a work around also. ref. Work around for background CSS[^]

here is my email body generated,

XML
<body>
    <table height="100%" width="100%" cellpadding="0" cellspacing="0" border="0" style="background-image: url('http://i.imgur.com/YJOX1PC.png');">
        <tr>
            <td valign="top" align="left" background="http://i.imgur.com/YJOX1PC.png">
                <!--[if gte mso 9]><v:image xmlns:v="urn:schemas-microsoft-com:vml" id="theImageTop" style='behavior: url(#default#VML); display:inline-block; position:absolute; height:131px; width:813px; top:0; left:0; right:0; bottom:0; border:0; z-index:1;' src="http://i.imgur.com/YJOX1PC.png"/><v:shape xmlns:v="urn:schemas-microsoft-com:vml" id="theTextTop" style='behavior: url(#default#VML); position:absolute; display:inline-block; height:131px; width:700px; border:0; z-index:2;'><![endif]-->
                <p>
                    Dear User,</p>
                <p>
                    Age is just a number.</p>
                <p>
                    Thanks and Regards.</p>
                <p>
                    </p>
                <!--[if gte mso 9]></v:shape><![endif]-->
            </td>
        </tr>
    </table>
</body>



When i revived mail in outlook and outlook.com image is not getting displayed.
I guess i am doing some mistake while dealing with VML tags.

Any suggestion is highly appreciable.

Thanks.
Posted
Updated 18-Mar-15 20:39pm
v2

1 solution

MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("venkat@gmail.com");
mailMessage.To.Add(new MailAddress("msdotnettechies@gmail.com"));
mailMessage.CC.Add(new MailAddress("user1@gmail.com"));
mailMessage.Bcc.Add(new MailAddress("user2@gmail.com"));
mailMessage.Subject = "Email Checking Asynchronously";
mailMessage.Body = "Email test asynchronous";
mailMessage.IsBodyHtml = true;//to send mail in html or not

SmtpClient smtpClient = new SmtpClient();//portno here
smtpClient.Host = "smtp.gmail.com";
smtpClient.EnableSsl = true ; //True or False depends on SSL Require or not
smtpClient.Credentials = new NetworkCredential("yourGmail@gmail.com", "yourpassword");
//smtpClient.UseDefaultCredentials = true; //true or false depends on you want to default credentials or not
Object mailState = mailMessage;

//this code adds event handler to notify that mail is sent or not
smtpClient.SendCompleted += new SendCompletedEventHandler(smtpClient_SendCompleted);
try
{
smtpClient.SendAsync(mailMessage, mailState);
}
catch (Exception ex)
{
Response.Write(ex.Message);
Response.Write(ex.StackTrace);
}

// this is the event called on main method
void smtpClient_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
MailMessage mailMessage = e.UserState as MailMessage;
if (e.Cancelled || e.Error != null)
{

Response.Write(e.Error.Message);
Response.Write(e.Error.StackTrace);
}
else
{
Response.Write("Email sent successfully");
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900