faranjit
faranjit

Reputation: 1637

System.Net.Mail.SmtpClient deletes some of my html and css tags

I wanna send a mail which formatted as html. I can do that but the mail comes wrong. When I open the source of the mail i saw that some of my styles and tags are removed but i do not know why. For example;

This is I want to send:

<div class="root-container">
    <div class="section">
        ...
    </div>
<div>

This is I received:

<div class="section">
    ...
</div>

This is my css style:

div.root-container {
        padding: 1rem;
        position: relative;
        background: linear-gradient(to right, #13a455, #0a5ca4);
        padding: 5px;
    }

This is received style:

.ROOT-CONTAINER {
    padding: 1rem;
    background: linear-gradient(to right, #13a455, #0a5ca4);
 }

C# Code:

var mail = new MailMessage();
mail.From = new MailAddress(accountContract.FromAdress, accountContract.FromName);
mail.Subject = messageContract.Subject ?? "";
mail.IsBodyHtml = true;
mail.Body = messageContract.Body;

using (var smtp = new SmtpClient())
{
    try
    {
        smtp.Credentials = new NetworkCredential(accountContract.MailUser, accountContract.MailPassword);
        smtp.Host = accountContract.Server;
        smtp.Send(mail);
    }
    catch (SmtpException ex)
    {
        WriteLog(messageContract.MessageId, "SmtpClient", null, ex.ToString());
        return MailStatus.UnProcessed;
     }                   
}

I am trouble with that problem for days. I would be really appreciated it if you could help me.

Upvotes: 1

Views: 446

Answers (1)

So_oP
So_oP

Reputation: 1293

Email HTML readers require a mixture of inline styles and, in some clients, HTML-based style markup.

HTML just requires everything to be included inside the (no tag, no scripts, and no external resources.). In other words for example you have to use inline styles of css instead of referencing them .

Upvotes: 2

Related Questions