当前位置: 首页 > 知识库问答 >
问题:

如何使用perl和sendmail[Mail::sendmail]从URL发送pdf

孔俊友
2023-03-14

我有一个需要改变的遗留应用程序。它是用perl编写的,并使用send::mail向用户发送邮件。以前我们在电子邮件消息正文中发送链接,但现在他们想要pdf附件。PDF是使用php在另一台服务器上生成的。

工作流程将是

  1. 创建电子邮件正文
  2. 通过URL从另一台服务器获取pdf
  3. 将pdf作为附件添加到电子邮件中
  4. 发送它。

我想我可以用

use LWP::Simple;
unless (defined ($content = get $URL)) {
    die "could not get $URL\n";
}

获取URL的内容,但我不知道如何在sendmail中将该变量用作附件。当前的sendmail代码是:

my %maildata = (To  => $to,
        From    => 'OurSite - Billing <billing@ourSite.com>',
        Organization => 'OurSite, LLC      http://www.OurSite.com/',
        Bcc => 'sent-billing@ourSite.com',
        Subject => $subject{$message} || 'ourSite invoice',
        Message => $body
           );
print STDERR "notify1 now calling sendmail\n";
sendmail(%maildata) || print STDERR $Mail::Sendmail::error;

我的另一个问题是,我不知道如何确定我的sendmail版本(旧的freebsd系统)是否能够发送附件?

共有1个答案

公冶阳德
2023-03-14

好的,谢谢那些给我指明方向/愿意尝试的海报。

最后,我构建了一个mime主体,做了以下工作

use LWP::Simple;
use MIME::Base64;

unless (defined ($content = get $URL)) {
    die "could not get $URL\n";
} 
my $pdfencoded = encode_base64($content);  

my %maildata = (To  => $to,
        From    => 'OurSite - Billing <billing@ourSite.com>',
        Organization => 'OurSite, LLC      http://www.OurSite.com/',
        Bcc => 'sent-billing@ourSite.com',
        Subject => $subject{$message} || 'ourSite invoice',

           );

my $boundary = "====" . time() . "====";

$maildata{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
$maildata{'Message'} = "--".$boundary."\n"."Content-Type: text/plain\n".$body.
"\n--".$boundary."\nContent-Transfer-Encoding: base64\nContent-Type: 
application/pdf; name=\"invoice.pdf\"\n".$pdfencoded."\n--".$boundary."--";

sendmail(%maildata) || print STDERR $Mail::Sendmail::error;

这给了我一个手工构建的MIME格式的正文内容。

谢谢你的帮助!

 类似资料:
  • 我正在使用Laravel 7,我想使用sendemail驱动程序和Laravel Mail Facade发送电子邮件,因为当我使用php邮件功能时,它可以工作,但我想使用Laravel Mail Facade。 这是我的. env文件电子邮件配置 这是我在config/mail中的默认邮件。php 什么是正确的配置?如何使其工作?

  • 问题内容: 如果我不想通过SMTP而是通过sendmail发送邮件,是否有用于封装此过程的python库? 更好的是,是否有一个好的库可以抽象整个“ sendmail -versus- smtp”选择? 我将在大量的Unix主机上运行此脚本,其中只有一些在localhost:25上侦听;其中一些是嵌入式系统的一部分,不能设置为接受SMTP。 作为优良作法的一部分,我真的很想让库自己解决标头注入漏洞

  • Linux/UNIX下的老牌邮件服务器。 Sendmail作为一种免费的邮件服务器软件,已被广泛的应用于各种服务器中,它在稳定性、可移植性、及确保没有bug等方面具有一定的特色,且可以在网络中搜索到大量的使用资料。 Sendmail 授权协议

  • 本文向大家介绍linux下python使用sendmail发送邮件,包括了linux下python使用sendmail发送邮件的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了python使用sendmail发送邮件的具体代码,供大家参考,具体内容如下 参考链接:How do I send mail from a Python script? 使用linux下的sendmail程序来发

  • shell-sendmail 是使用sendmail命令发送邮件的shell脚本,可发送附件,支持中文。

  • 问题内容: 我花了整个上午在互联网上搜索此问题,以寻求有关此问题的解决方案。我已经在Windows 8.1上安装了wamp服务器,并且尝试通过sendmail(http://glob.com.au/sendmail/)和我的gmail帐户发送一些邮件 当我将sendmail配置为使用端口号465时,总是出现此错误:套接字错误#10060连接超时 如果尝试使用端口587,则会在错误日志中显示以下行: