通过电子邮件发送 SAS html 输出

2024-02-13

我正在使用 SAS Enterprise Guide 6.1。我正在尝试使用 Windows 调度程序对下面的程序进行批处理以生成每周报告。它将有一些过程打印和 sgplots。我将其发送给的用户是高级用户,并且没有 SAS(如果他安装了,将不知道如何处理该程序)。理想情况下,我只想通过电子邮件向他发送附件,甚至将图表/结果嵌入到电子邮件中,以便他可以查看它们。我的程序似乎正确创建了 html 文件,但是当我在电子邮件中打开它时,sgplots 没有显示。有什么想法吗?谢谢。

filename temp email to="[email protected] /cdn-cgi/l/email-protection"
                    subject="Testing the report"
                    type="text/html"
                    attach='/sasdata/cthulhu/email.html';

ods html path='/sasdata/cthulhu' file='email.html' gpath='/sasdata/cthulhu' style=htmlblue;

data have;
    input name $ class $ time score;
cards;
chewbacca wookie  1 97
chewbacca wookie 2 100
chewbacca wookie 3 95
saruman wizard 1 79
saruman wizard 2 85
saruman wizard 3 40
gandalf wizard 1 22
gandalf wizard 2 50
gandalf wizard 3 87
bieber canadian 1 50
bieber canadian 2 45
bieber canadian 3 10
;
run;

proc sql noprint;
    select count(distinct class) into :numclass
    from have;
    %let numclass=&numclass;
    select distinct class into :class1 - :class&numclass
    from have;
    select count(distinct name) into :numname
    from have;  
    %let numname=&numname;
    select distinct name into :name1 - :name&numname
    from have;
quit;

%macro printit;
%do i = 1 %to &numclass;
title "Report for &&class&i";
proc print data=have;
    where class="&&class&i";
run;
%end;
%mend;
%printit;

%macro plotit;
%do i = 1 %to &numname;
title "Plot for &&name&i";
proc sgplot data=have(where=(name="&&name&i"));
    series x=time y=score
    / legendlabel='score' markers lineattrs=(thickness=2);
    xaxis label="time";
    yaxis label='score';
run;
%end;
%mend;
%plotit;

ods html close;

data _null_;
   file temp;
   put 'This is a test';
run;

还有一种 DomPazz 没有提到的替代方案,为了完整起见,我将其放在这里。我愿意NOT推荐这种方法,除非您发现自己处于以下情况:

  1. 您不得使用附件。
  2. 您可以放置​​图像的唯一位置是 Intranet 或 HTTPS 服务器上。
  3. 电子邮件必须可以从智能手机读取(智能手机通常不会连接到公司 VPN 或无法提供 HTTPS 凭据来下载和显示图像)。

Cons

  • SAS 不直接支持此方法。
  • 它需要第三方工具(例如 BLAT -http://www.blat.net/ http://www.blat.net/).
  • 众所周知,HTML 电子邮件消息在呈现时非常挑剔,因此您必须保持它们简单。
  • 这不适合胆小的人。

Overview

基本前提是您在磁盘上将图表创建为图像,在磁盘上创建 HTML 文件,然后使用第 3 方工具发送电子邮件。第三方工具会将图表嵌入到电子邮件中,您创建的 HTML 将使用所谓的 CID(内容 ID)引用嵌入的图像。

我建议先阅读/谷歌搜索一下术语“html email cid”,以熟悉这一点。您可能还想阅读一些有关 Base64 编码和 MIME 类型的内容。您不需要成为专家,只需了解足够的知识即可了解它们是什么以及它们大致如何工作。

开发/测试

您仍然可以使用 ODS 来创建您的.html文件但一定要使用ODS HTML3这会强制 SAS 使用旧版本的 HTML。它还迫使它对每个元素重复样式。您需要这个,因为 Outlook 等电子邮件客户端实际上使用 MS Word 引擎来呈现 HTML 电子邮件。

构建 .html 文件和图表后,在 Web 浏览器中打开 .html 文件并确保其正确显示。

在网络浏览器中按照需要显示输出后,您还需要进行一些更改,然后才能将其作为电子邮件发送。在浏览器中进行开发时,您会注意到您嵌入了如下图像:

<img src="my_image.png" />

我们不能对电子邮件执行此操作,我们需要使用 CID 链接,如下所示:

<img src="cid:my_image.png" />

当我们使用 BLAT 发送电子邮件时,我们将指定要嵌入的图像。图像名称将自动用于CID:命名约定。

您可以使用 BLAT 发送电子邮件,如下所示:

blat test.html -f "[email protected] /cdn-cgi/l/email-protection" -subject "test" -html -alttextf test.html -embed test.png -server mail.mysmtpserver.com -to [email protected] /cdn-cgi/l/email-protection 

就是这样。也许如果我有更多时间,我会提供完整的代码和一个工作示例。

一些有用的阅读:

http://24ways.org/2009/rock-solid-html-emails http://24ways.org/2009/rock-solid-html-emails(读这个!!)

http://www.emailology.org http://www.emailology.org

http://www.campaignmonitor.com/css/ http://www.campaignmonitor.com/css/

HTML 电子邮件对齐文本 https://stackoverflow.com/questions/9989657/html-email-align-text

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过电子邮件发送 SAS html 输出 的相关文章