如何使CSS动画在电子邮件中起作用?

问题描述 投票:-1回答:1

我正在尝试学习如何通过电子邮件发送CSS动画,但是当我向自己的Outlook发送一个CSS动画示例时,它不起作用。即使当我尝试在单独的浏览器中打开时,所看到的只是一张红色图片,并且没有预期的动画。我正在使用SmtpClient类,并且已激活isbodyhtml = true

我想在我的电子邮件中查看动画。我尝试找到如何在电子邮件中发送CSS动画的完成示例,但没有一个起作用。

string smtpserver = "XXXX.XXXX.XXXX";
int smtpport = 25;
NetworkCredential credentials = null;
bool enableSSL = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = smtpserver;
smtp.Port = smtpport;
smtp.Credentials = credentials;
smtp.EnableSsl = enableSSL; //smtp.EnableSsl = true;
Console.WriteLine("Sending email to [" + toEmail + "] with [" + smtpserver.ToString() + ":" + smtpport.ToString() + "]");
MailMessage mail = new MailMessage();
mail.From = new MailAddress(fromEmail);
string[] mailAddresses = toEmail.Split(';');

foreach (string mailAddress in mailAddresses)
{
    mail.To.Add(new MailAddress(mailAddress));
}

mail.Subject = "Urgent! Disco Disco!";
body = @""+
"<!DOCTYPE html>"+
"<html>"+
"<head>"+
"<style>"+
"div {"+
"  width: 100px;"+
" height: 100px;"+
" background - color: red;"+
" -webkit - animation - name: example; /* Safari 4.0 - 8.0 */"+
" -webkit - animation - duration: 4s; /* Safari 4.0 - 8.0 */"+
" animation - name: example;"+
" animation - duration: 4s;"+
"}"+
"/* Safari 4.0 - 8.0 */"+
"@-webkit - keyframes example {"+
"   from { background - color: red; }"+
"  to { background - color: yellow; }"+
"}"+
"/* Standard syntax */"+
"@keyframes example {"+
"from { background - color: red; }"+
"to { background - color: yellow; }"+
"}"+
"</style>"+
"</head>"+
"<body>"+
"<p><b> Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>"+
            "<div></div>"+
"<p><b> Note:</b> When an animation is finished, it changes back to its original style.</p>"+
"</body>"+
"</html>";
mail.Body = body;
mail.IsBodyHtml = true;

try
{
    if (files != null)
    {
        foreach (string file in files)
        {
            mail.Attachments.Add(new Attachment(file));
        }
    }
}
catch (Exception ex)
{
    Console.WriteLine("Error attaching attachment" + "[" + ex.Message + "]");
}
AutoResetEvent waiter = new AutoResetEvent(false);
smtp.SendCompleted += (s, e) => { mail.Dispose(); };
smtp.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
smtp.SendAsync(mail, waiter);
waiter.WaitOne(5000);
Console.WriteLine("SendAsync completed.");
c# css css-animations smtpclient
1个回答
0
投票

您是否可以不使用此"<h1> test </h1>"

我已经尝试了铬和边缘,它没有动画

这是我尝试过的

<!DOCTYPE html>
<html>
<head>
<title>myTitle</title>
<style>
div {
  width: 100px;
 height: 100px;
 background-color: "red";
 -webkit-animation-name: "example"; /* Safari 4.0 - 8.0 */
 -webkit-animation-duration: 4s; /* Safari 4.0 - 8.0 */
 animation-name: example;
 animation-duration: 4s;
}
/* Safari 4.0 - 8.0 */
@-webkit-keyframes "example" {
   from { background-color: red; }
  to { background-color: yellow; }
}
/* Standard syntax */
@keyframes example {
from { background-color: red; }
to { background-color: yellow; }
}
</style>
</head>
  
<body>
<p><b> Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
            <div></div>
<p><b> Note:</b> When an animation is finished, it changes back to its original style.</p>
</body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.