【问题标题】:How can I send the content of file as email in Perl?如何在 Perl 中将文件内容作为电子邮件发送?
【发布时间】:2016-01-04 06:09:10
【问题描述】:

附件代码

$msg->attach(Type        => 'document/text',

         Path        => "C:\\SDB_Automation\\sdb_dump.txt",
         Filename    => 'sdb_dump.txt',
         Disposition => 'attachment'
        );       
$msg->send;

我已经在文本文件中打印数据并将其保存在我的本地机器中。但由于订阅者的原因,我只想发送该文件的数据而不是那个文本文件。

【问题讨论】:

  • 您不想附加文件,而是将其内容发送到电子邮件正文中?有什么问题?
  • 如果您告诉我们$msg 是哪种类型的对象,对您的帮助会容易得多。 Perl 有许多用于创建和发送电子邮件的模块——您要求我们猜测您正在使用哪个模块。
  • 好数据在 txt 文件中,我想通过 perl 脚本通过邮件发送它,但我是 perl 的新手,我正在寻求帮助,所以可能有人可以帮助我吗?

标签: perl file email text


【解决方案1】:

Perl 有许多模块可以提供帮助。例如尝试啜饮。希望对您有所帮助。

use Email::MIME;
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP::TLS;
use Path::Class qw/file/;
use File::Type;
use MIME::Base64;
$file= file(path);
$file = scalar $file->slurp;
my $newpart = Email::MIME->create(
          attributes => {
                content_type => type,
                encoding => base64,
                disposition => $attachment->{disposition}, # maybe useful rfc2387
                charset => undef,
                name => 'attachment',
                },
                body => $file,
         );
push @parts , $newpart;
my $email = Email::MIME->create(
            header => [
                From        => " ",
                To          => "",
                Subject     => "",
                'Reply-To'  => "",
            ],
            parts => [@parts],
        );
Email::Sender::Simple->send($email)

【讨论】:

  • 非常感谢您的帮助,但我尝试使用 Outlook 并成功了:P code open my $fh, ' };关闭 $fh 或死亡 "Ugh: $!\n";打印 $text1,"\n"; code 和 $message->Body("$text1");
猜你喜欢
  • 2018-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-24
  • 1970-01-01
  • 2015-05-10
  • 2015-06-27
相关资源
最近更新 更多