2016-11-01 102 views
2

安全性の低いアプリへのアクセスを許可した後hereインラインスタイリングでGmailを使用してメールを送信することができました。MailKitのHTMLメール本体のフォントの変更とスタイリング

using MailKit.Net.Smtp; // for SmtpClient 
using MimeKit; // for MimeMessage, MailboxAddress and MailboxAddress 

var message = new MimeMessage(); 
message.From.Add(new MailboxAddress("Hasan Yousef", "[email protected]")); 
message.To.Add(new MailboxAddress("Personal", "[email protected]")); 
message.To.Add(new MailboxAddress("Office", "[email protected]")); 
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("[email protected]", "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のフォント表示が私の見通しに表示されるフォントよりも完全に異なっているので、私は誰もがそれを彼が使用しているものは何でも電子メールクライアントと同じように読み込みを保証するために、フォントを統一する必要が気づきました。電子メールでの上記E.B.コメントを1として

+2

あなたは[この](http://stackoverflow.com/questions/8012799/do-we-still-need-to-use-font-tags-in-html-emails)トピックを確認しましたか?それは同じ問題のようです... すべてのメールクライアントで許容されるフォントを設定するには、このサイトもご覧ください:https://www.campaignmonitor.com/css/ –

答えて

1

、およびthisthisに参照のうえと考えるとCSSが異なるブラウザおよび/または電子メールクライアントに異なる方法で処理されて、私が見つけた私のために最も適したオプションは以下のとおりインラインスタイルを使用しています:

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