字体改变和样式的HTML电子邮件正文在MailKit



在允许访问不太安全的应用程序之后,我可以使用内联样式的gmail给自己发送电子邮件了。

using MailKit.Net.Smtp;   // for SmtpClient
using MimeKit;  // for MimeMessage, MailboxAddress and MailboxAddress
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Hasan Yousef", "hasan@gmail.com"));
message.To.Add(new MailboxAddress("Personal", "hasan@gmail.com"));
message.To.Add(new MailboxAddress("Office", "hasan@offfice.com.sa"));
message.Subject = "How you doin'?";
string num = "13.5 million";
var bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = @"
<div style='background-color:black;color:white;padding:20px; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);'>
            <h1 style='text-align: center; font-family: 'Sigmar One', cursive;'>Welcome to Ben's Minecraft</h1>
            <img src='https://www.bk-international.com/mahout_cms/project/themes/default/images/de/logo.png' alt='HTML5' style='width:84px;height:47px'><br>
            <a href='https://www.bk-international.com/de_en/'>Bischof + Klein</a>
            <h2>London</h2>
            <p>London is the capital city of England. 
            It is the most populous city in the United Kingdom, with a metropolitan area of over <span style='color:red'>
<i><b>" + num + 
@"</b></i></span>
inhabitants.</p>
            <p style='background-color:#ffc;color:black;'> Hope you liked the above</p>
            <table>
            <tr>
                <th>Name</th>
                <th>Description</th>
            </tr>
            <tr>
                <td>A</td>
                <td>Description of A</td>
            </tr>
            <tr>
                <td>B</td>
                <td>Description of B</td>
            </tr>
            </table>
            <ol>
                <li>London</li>
                <li>Paris</li>
                <li>Tokyo</li>
            </ol>
            <img src='https://www.bk-international.com/mahout_cms/project/themes/default/images/subhead.png' alt='HTML5' style='width:193px;height:9px'>
</div>         
            ";
message.Body = bodyBuilder.ToMessageBody();
/*       message.Body = new TextPart("plain")
        {
            Text = @"Hey Chandler,I just wanted to let you know that Monica and I were going to go play some paintball, you in?-- Joey"
        };
*/
using (var client = new SmtpClient())
{
      client.Connect("smtp.gmail.com", 587);
      client.AuthenticationMechanisms.Remove("XOAUTH2");  // due to enabling less secure apps access
      client.Authenticate("hasan@gmail.com", "myEmailPassward");
      client.Send(message);
      client.Disconnect(true);
}

我的问题是:我怎么能改变字体,我试着在下面添加头部脚本,但它没有工作。

<head>
   <link href='https://fonts.googleapis.com/css?family=Sigmar+One' rel='stylesheet' type='text/css'>
</head>

我注意到gmail中的字体显示与我的outlook中显示的字体完全不同,所以我需要统一字体,以确保每个人都能以相同的方式阅读,无论他使用什么电子邮件客户端

根据E.B.上面的评论,参考这一点和这一点,考虑到电子邮件中的CSS在不同的浏览器和/或电子邮件客户端中处理方式不同,我发现最合适的选择是使用内联样式,如下所示:

<div style='background-color:black;color:white;padding:20px; font-family:Arial, Helvetica;color:#555555;font-size:12px;'>

最新更新