如何在从 Perl CGI 脚本发送的 HTML 电子邮件中包含 CSS 文件?

发布于 2024-07-29 05:57:39 字数 1157 浏览 3 评论 0原文

我正在使用以下代码通过 CGI perl 创建和发送电子邮件。 图像已正确附加,但 css 文件未正确附加。

  my $msg = new MIME::Lite(
            From    => $from,
            To      => $to_list,
            Subject => "My subject",
            Type    => 'text/html',  # 'multipart/mixed'
            Data    => $body
           );
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/fonts-min.css");
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/eat.css");
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/site_styles2.css");
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/calendar_layout.css");
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/errnacc.css");
 $msg->attach(Type => 'image/png',    Path => $DOCS_URL . "/separator.gif");
 $msg->attach(Type => 'image/png',    Path => $DOCS_URL . "/trans_pixel.gif");
 $msg->attach(Type => 'image/png',    Path => $DOCS_URL . "/itg_side.gif");

 $msg->send();

图像已正确附加,但 css 文件根本未附加。 知道应该使用什么“类型”来附加 CSS 文件吗? 或者还有其他问题吗?

I am using following code to create and send email through CGI perl. The images get attached properly, but the css files do not.

  my $msg = new MIME::Lite(
            From    => $from,
            To      => $to_list,
            Subject => "My subject",
            Type    => 'text/html',  # 'multipart/mixed'
            Data    => $body
           );
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/fonts-min.css");
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/eat.css");
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/site_styles2.css");
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/calendar_layout.css");
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/errnacc.css");
 $msg->attach(Type => 'image/png',    Path => $DOCS_URL . "/separator.gif");
 $msg->attach(Type => 'image/png',    Path => $DOCS_URL . "/trans_pixel.gif");
 $msg->attach(Type => 'image/png',    Path => $DOCS_URL . "/itg_side.gif");

 $msg->send();

The images get attached properly, but the css files are not attached at all.
Any idea what 'Type' should be used to attach CSS files?
Or is there any other problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

但可醉心 2024-08-05 05:57:39

我相信 text/css 应该没问题

I believe text/css should be OK

画骨成沙 2024-08-05 05:57:39

根据我的测试,许多电子邮件客户端只是在显示电子邮件之前删除所有 head 元素。 因此,如果您必须支持多种电子邮件客户端,那么使用外部样式表是不可行的。

我的建议是将样式直接包含到 HTML 中,尽管这很痛苦。

From my tests, many email clients simply remove all the head elements before displaying an email message. Therefore, using external style sheets isn't feasible if you have to support a wide range of email clients.

My advice is to include styling directly into the HTML, as painful as that is.

已下线请稍等 2024-08-05 05:57:39

我不得不说,如果您尝试使用脚本执行的操作是发送 HTML 格式的电子邮件,即使您将 CSS 文件作为附件发送,它也不会起作用。

唯一有信心做到这一点的方法是发送带有使用绝对 URL 链接的所有外部文件的 HTML。 即使那么它也不会按照您期望的方式工作。

I have to say, if what you're trying to do with your script is send HTML-formatted email, even if you get the CSS files sent as attachments, it's not going to work.

The only way to do this with any confidence at all is to send HTML with all external files linked using absolute URLs. And even then it won't work the way you expect it to.

疾风者 2024-08-05 05:57:39

尝试使用内联 css ...它可以工作(请参阅 http://www.tizag.com/cssT/内联.php)

Try using inline css ...it works (see http://www.tizag.com/cssT/inline.php)

悲歌长辞 2024-08-05 05:57:39

我认为你已经得到了答案,但在我看来,好的方法是,不要直接放置 html 代码,而是使用一些基于 html 的邮件信封,在单独的 html 文件中包含消息和占位符,然后解析和替换占位符,以便你可以轻松使用 CSS我认为它也很容易维护。

I think you already got your answer but in my opinion good way is, instead of putting html code directly, use some html based mail envelope having message and placeholders in separate html file and then parse and replace placeholders so that you can use CSS easily and i think it will be easy to maintain too.

贱人配狗天长地久 2024-08-05 05:57:39

刚刚遇到同样的问题。 你可以尝试这个工具,http://templates.mailchimp.com/resources/inline-css/
请记住保存原始模板的副本,以备需要更新时使用

just came across same issue. you may try this tool, http://templates.mailchimp.com/resources/inline-css/
remember to save the copy of original template in case you need to update

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文