perl - 生成带有 Excel XLSX 附件的电子邮件
问题描述
当我尝试打印整个字符串或编码部分时,以下 Perl 程序在第 44 行给出拒绝访问错误。如果我只打印标题使用$msg->print_header(\*STDOUT)
.
我要做的是生成一个文本文件,其中包含可用于 telnet 命令的所有信息,以通过发送带有附件的电子邮件来测试消息传输代理(MTA)。
use MIME::Lite;
use Net::SMTP;
### Add the sender, recipient and your SMTP mailhost
my $from_address = 'temp999 at gmail.com';
my $to_address = 'test05@gmail.com';
my $mail_host = 'gmail.com';
### Adjust subject and body message
my $subject = 'Testing script';
my $message_body = "I am sending an email with an attachment";
### Adjust the filenames
my $my_file_xlsx = 'c:/temp';
my $your_file_xlsx = 'count.xlsx';
### Create the multipart container
$msg = MIME::Lite->new(
From => $from_address,
To => $to_address,
Subject => $subject,
Type => 'multipart/mixed'
) or die "Error creating multipart container: $!\n";
### Add the text for the message body
$msg->attach(
Type => 'TEXT',
Data => $message_body
) or die "Error adding the text message part: $!\n";
### Adding an Excel file
$msg->attach(
Type => 'application/octet-stream',
Path => $my_file_xlsx,
Filename => $your_file_xlsx,
Disposition => 'attachment'
) or die "Error adding $file_xls: $!\n";
### Send the Message
MIME::Lite->send('smtp', $mail_host, Timeout => 60);
#$msg->send;
$msg->print(\*STDOUT); # Write to a file handle ### LINE 44 ###
#$msg->print_header(\*STDOUT); # Write the header
#$msg->print_body(\*STDOUT); # Write the encoded body
我没有找到任何与我想要做的完全匹配的东西,但我在搜索时可能没有使用正确的术语。
解决方案
您正在尝试附加文件c:/temp
,它(可能)是一个目录,而不是一个文件。当 MIME::Lite 尝试将其作为文件打开以读取内容时,它会因该错误而失败。您可能打算c:/temp/count.xlsx
通过Path
.
推荐阅读
- algorithm - 计算三项式系数的上限
- r - 按降序重新排列闪避图
- vba - 如何让 Microsoft Access 将文件尺寸保存到表中?
- react-native - 如何在 graphQL 模式中定义从我的应用程序发送到后端的图像?
- c# - 如何在 .NET Framework 中调用本机 CLR 方法?
- reactjs - useEffect 与 useContext 陷入无限循环
- c - 如何在寄存器中定义标志的宽度
- javascript - Web3.js--getBalance到web3.utils.fromWei,将值存储在一个变量中,用于表中
- javascript - firebase-ui-auth firebaseui.auth 未定义
- typescript - 无法解析模块“firebase-admin/app”的路径(ESLint)