我有一个文本文件。我已经使用一个小的搜索模式算法将其分离,我得到了预期的输出
chomp(@ARGV);
if (@ARGV != 2)
{
print "Please Pass two parametersn";
print "Usage: nt $0 <Filename> <pattern>n";
exit;
}
$File_name = $ARGV[0];
$res_File_name = $File_name . ".result.txt";
$Pattern = $ARGV[1]; chomp($Pattern);
open(FD,"$File_name") or die("File $File_name could not be openedn");
open(WFD,">$res_File_name") or die("File $res_File_name could not be openedn");
while(<FD>)
{
print WFD $_ if(/$Pattern/);
}
close(FD);
close(WFD);
但当搜索完成后,我只提取文本文件中的那些模式,并将其放在本地驱动器中。相反,我需要将该文本文件附加在电子邮件中,并需要将其发送出去。为此,我使用office 365,如果它显示电子邮件发送成功,但我没有收到任何带有附件的电子邮件
使用MIME::Lite;
use Net::SMTP;
use Mail::Sendmail1;
use Net::SMTP::TLS;
#use strict;
if (@ARGV != 2)
{
print "Please Pass two parametersn";
print "Usage: nt $0 <Filename> <pattern>n";
exit;
}
$File_name = $ARGV[0];
$res_File_name = $File_name . ".result.txt";
$Pattern = $ARGV[1]; chomp($Pattern);
open(FD,"$File_name") or die("File $File_name could not be openedn");
open(WFD,">$res_File_name") or die("File $res_File_name could not be openedn");
while(<FD>)
{
print WFD $_ if(/$Pattern/);
}
$to = 'xx@xx.com';
#$cc = 'xx@xx.com';
$from = 'xx@xx.com';
$subject = 'Test Email';
$message = 'This is test email sent by Perl Script';
open (txt.result.txt, '<', $res_File_name) or die "Failed to open $log_file: $!";
@log_contents = <txt.result.txt>;
close txt.result.txt;
push @body, @log_contents;
#open MAIL, '|C:PerlsitelibMailSendmail1 -t' or die "Failed to send mail: $!";
$msg = MIME::Lite->new(
From => $from,
To => $to,
#Cc => $cc,
Subject => $subject,
Type => 'multipart/mixed'
);
#print MAIL "To: ${to}n";
#print MAIL "From: ${from}n";
#print MAIL "Subject: ${subject}nn";
# email body
#print MAIL @body;
# Add your text message.
$msg->attach(Type => 'result.txt',
Data => $message
);
#$msg->send;
#attach=( "Agent.txt.result.txt" )
close(FD);
close(WFD);
#close MAIL;
print "Email sent successfully.n";
exit;
#print "Email Sent Successfullyn";
Help me on how i can achieve this.
我认为您有一个拼写错误:use Mail::Sendmail1
应该是Mail::Sendmail
(没有"1")。但使用MIME::Lite
并不需要Mail::Sendmail
。
我建议您使用其他模块来发送邮件,如电子邮件::Simple