当我尝试打印整个字符串或编码部分时,以下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
我没有找到与我要执行的操作完全匹配的内容,但搜索时可能未使用正确的术语。
答案 0 :(得分:3)
您正在尝试附加文件c:/temp
,该文件{可能是目录,而不是文件。当MIME :: Lite尝试将其作为文件打开以读取内容时,它将失败并显示该错误。您可能打算将c:/temp/count.xlsx
作为Path
传递。