gpt4 book ai didi

c# - 发送 html 电子邮件时,内联 css 样式未正确应用

转载 作者:行者123 更新时间:2023-11-28 01:23:19 25 4
gpt4 key购买 nike

我正在尝试通过 C# 代码发送带有 html 的邮件,但它在 Gmail 上无法正确呈现。有人可以让我知道我做错了什么吗..

 MailMessage msg = new MailMessage();

msg.From = new MailAddress("no.reply.checkarr@gmail.com");
msg.To.Add(ReciverMail);
msg.Subject = title;


String bodyBuilder = "";

bodyBuilder += "<div style = \"font - family: Calibri, Arial; background - image: url('https://www.aqeqah.com/wp-content/uploads/pattern-07.jpg'); background - color: transparent; background - position: center center; background - repeat: repeat; background - attachment: fixed; position: fixed; width: 100 %; height: 100 %; left: 0; top: 0; \">";
bodyBuilder += " <div style = \"margin: 0 auto; width: 90 %; border: 1px solid grey; text - align: center; background - color: white; border - radius: 5px; margin - top: 5 %; box - shadow: 0 16px 26px 0 rgba(0, 0, 0, 0.2), 0 6px 26px 0 rgba(0, 0, 0, 0.19); \">";
bodyBuilder += " <h1 style = \"color: #ff1017;\">Checkarr</h1>";
bodyBuilder += " <p style = \"padding - left: 5 %; padding - right: 5 %; \">We are sending this mail to you to inform about important updates for your account</p>";
bodyBuilder += " <h2>Account Verification</h2>";
bodyBuilder += " <p style = \"padding - left: 5 %; padding - right: 5 %; \">It looks like it's a great time to verify your account. Verified account are subjected to get best out of our services. Either use the following code to verify your account or click the button.</p>";
bodyBuilder += " <h3 style=\"color: grey; border: 3px dashed #ff1017; width: 100px; height: 30px;margin:0 auto; padding-top: 10px; border-radius: 5px\">ASDF32</h3>";
bodyBuilder += " <p style = \"color: grey\"> OR</p>";
bodyBuilder += " <button style=\"background - color: #ff1017;border: none;color: white;padding: 20px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;margin: 4px 2px;border-radius: 5px;cursor: pointer;\">Verify Account</button>";
bodyBuilder += " <p>Stay awesome!</p><br/><br/>";
bodyBuilder += " <p style = \"color: grey; font - size: 10px\">This is auto generated mail. Please don't reply</p>";
bodyBuilder += " <p style = \"color: grey; font - size: 10px\">Checkarr © - Islamabad, Pakistan </br>www.checkarr.pk</p>";
bodyBuilder += " </div>";
bodyBuilder += "</div>";



msg.Body = bodyBuilder;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = true;
client.Host = "smtp.gmail.com";
client.Port = 587;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new NetworkCredential("no.reply.checkarr@gmail.com", "/*PASS REMOVED*/");
client.Timeout = 20000;
try
{
client.Send(msg);
System.Diagnostics.Debug.WriteLine("Mail has been successfully sent!");
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Exception while sending mail" + ex.Message);
}
finally
{
msg.Dispose();
}

它在 gmail 上的样子

outcome

** 浏览器中的 html View ——它应该是怎样的 **

enter image description here

最佳答案

bodyBuilder 字符串中存在一些格式问题。例如“字体 - 系列”我将它们更改为喜欢“字体系列”并解决了问题。我想我应该 sleep 了 :3

关于c# - 发送 html 电子邮件时,内联 css 样式未正确应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51369863/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com