2016-11-25 22 views
0

私は電子メールを送信するこのaspx機能を持っています。残念ながら、GmailやOutlookでhtmlタグを表示しませんが、Android端末ではうまく見えます。それを修正するには?ありがとう。ASPX電子メールHTML形式

protected void SendMail() 
{ 

    var fromAddress = "[email protected]"; 
     var toAddress = "[email protected]"; 


     const string fromPassword = "****"; 
     var subject = "subject";   


    string body = " <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\">"; 
    body += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=utf-8\">"; 
    body += "</HEAD><BODY>"; 
    body += "<b>some text some text</b><br></br>"; 
    body += "</BODY></HTML>"; 



    var smtp = new System.Net.Mail.SmtpClient(); 
    { 

     smtp.Host = "smtp.gmail.com"; 
     smtp.Port = 587; 
     smtp.EnableSsl = true; 
     smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; 
     smtp.Credentials = new NetworkCredential(fromAddress, fromPassword); 
     smtp.Timeout = 20000; 
    } 
    smtp.Send(fromAddress, toAddress, subject, body); 
} 

EDITED: これは私が今持っているものです。コンパイラはこのエラーを返します。 行392:mail.From = fromAddress; コンパイラエラーメッセージ:CS0029:暗黙的に型 'string' を変換できません 'System.Net.Mail.MailAddress'

var fromAddress = "[email protected]***"; 
         var toAddress = "*****@gmail.com"; 
         const string fromPassword = "******"; 
         var subject = "New Project Started!"; 
         string body = "<b>TA:</b>"; 

         MailMessage mail= new MailMessage(); 
         mail.From = fromAddress; 
         mail.To = toAddress; 
         mail.Subject = subject; 
         mail.IsBodyHtml = true; 
         mail.Body = body; 

     var smtp = new System.Net.Mail.SmtpClient(); 
     { 

      smtp.Host = "smtp.gmail.com"; 
      smtp.Port = 587; 
      smtp.EnableSsl = true; 
      smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; 
      smtp.Credentials = new NetworkCredential(fromAddress, fromPassword); 
      smtp.Timeout = 20000; 
     } 

         smtp.Send(mail); 

EDITED: 私の作業溶液:

using System.Net; 
using System.Net.Mail; 
using System.Net.Mime; 

       var fromAddress = "****"; // mail Address from where you send the mail 
       var toAddress = "****"; 
       const string fromPassword = "***"; //Password of your gmail address 
       var subject = "New Job Created!"; 

       // set smtp-client with basicAuthentication 
       SmtpClient mySmtpClient = new SmtpClient("smtp.gmail.com"); 
       mySmtpClient.Port = 587; 
       mySmtpClient.EnableSsl = true; 
       mySmtpClient.UseDefaultCredentials = false; 
       System.Net.NetworkCredential basicAuthenticationInfo = new 

       System.Net.NetworkCredential(fromAddress, fromPassword); 
       mySmtpClient.Credentials = basicAuthenticationInfo; 

       // add from,to mailaddresses 
       MailAddress from = new MailAddress(fromAddress, ""); 
       MailAddress to = new MailAddress(toAddress, "Devision"); 
       MailMessage myMail = new System.Net.Mail.MailMessage(from, to); 

       // set subject and encoding 
       myMail.Subject = subject; 
       myMail.SubjectEncoding = System.Text.Encoding.UTF8; 

       // set body-message and encoding 
       myMail.Body = "<b>TEST</b>"; 
       myMail.BodyEncoding = System.Text.Encoding.UTF8; 

       // text or html 
       myMail.IsBodyHtml = true; 

       mySmtpClient.Send(myMail); 

答えて

1

MailMessageクラスを作成します。 。重要なことは、HTMLのBodyがプロパティで行われることを指定することです。IsBodyHtml

MailMessage mail= new MailMessage(); 
mail.From = fromAddress; 
mail.To = toAddress; 
mail.Subject = subject; 
mail.IsBodyHtml = true; 
mail.Body = body; 

//other stuff 

smtp.Send(mail); 
関連する問題