Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl-使用搜索模式隔离文本文件并自动通过电子邮件发送附件_Perl_Email - Fatal编程技术网

Perl-使用搜索模式隔离文本文件并自动通过电子邮件发送附件

Perl-使用搜索模式隔离文本文件并自动通过电子邮件发送附件,perl,email,Perl,Email,我有一个文本文件。我已经使用一个小的搜索模式算法将其分离,并得到了预期的输出 chomp(@ARGV); if (@ARGV != 2) { print "Please Pass two parameters\n"; print "Usage: \n\t $0 <Filename> <pattern>\n"; exit; } $File_name = $ARGV[0]; $res_File_name = $File_name .

我有一个文本文件。我已经使用一个小的搜索模式算法将其分离,并得到了预期的输出

chomp(@ARGV);

if (@ARGV != 2)
 {

    print "Please Pass two parameters\n";
    print "Usage: \n\t $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 opened\n");
open(WFD,">$res_File_name") or die("File $res_File_name could not be opened\n");

while(<FD>) 
{

    print WFD $_ if(/$Pattern/);
}

close(FD);
close(WFD);
chomp(@ARGV);
如果(@ARGV!=2)
{
打印“请传递两个参数\n”;
打印“用法:\n\t$0\n”;
出口
}
$File_name=$ARGV[0];
$res\u File\u name=$File\u name。“\.result\.txt”;
$Pattern=$ARGV[1];咀嚼(模式);
打开(FD,“$File\u name”)或死亡(“无法打开文件$File\u name”);
打开(WFD,“>$res_File_name”)或死亡(“无法打开文件$res_File_name”);
while()
{
打印WFD$\uIf(/$Pattern/);
}
关闭(FD);
关闭(WFD);
但当搜索完成后,我只提取文本文件中的模式,并将其放在本地驱动器中。相反,我需要将该文本文件附加到电子邮件中,并需要将其发送给其他人。为此,我正在使用office 365,因为它显示电子邮件已成功发送,但我未收到任何带有附件的电子邮件

使用MIME::Lite

use Net::SMTP;
 use Mail::Sendmail1;
  use Net::SMTP::TLS; 
 #use strict;
if (@ARGV != 2)
 {

    print "Please Pass two parameters\n";
    print "Usage: \n\t $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 opened\n");
open(WFD,">$res_File_name") or die("File $res_File_name could not be opened\n");

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:\Perl\site\lib\Mail\Sendmail1 -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}\n\n";

# 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 Successfully\n";





    Help me on how i can achieve this. 
使用Net::SMTP;
使用Mail::Sendmail1;
使用Net::SMTP::TLS;
#严格使用;
如果(@ARGV!=2)
{
打印“请传递两个参数\n”;
打印“用法:\n\t$0\n”;
出口
}
$File_name=$ARGV[0];
$res\u File\u name=$File\u name。“\.result\.txt”;
$Pattern=$ARGV[1];咀嚼(模式);
打开(FD,“$File\u name”)或死亡(“无法打开文件$File\u name”);
打开(WFD,“>$res_File_name”)或死亡(“无法打开文件$res_File_name”);
while()
{
打印WFD$\uIf(/$Pattern/);
}
$to$xx@xx.com';
#$cc='1xx@xx.com';
$fromxx@xx.com';
$subject='testemail';
$message='这是由Perl脚本发送的测试电子邮件';

打开(txt.result.txt,“我想您有一个输入错误:
使用Mail::Sendmail1
应该是
Mail::Sendmail
(不带“1”)。但是使用
MIME::Lite
不需要
Mail::Sendmail


我建议您使用其他模块来发送邮件,如

是的,我修改了perl模块并将其重命名为sendmail1。无论是什么,此方法都将与sendmail1通信,sendmail1在命名空间和脚本的其他部分中声明