2012-11-13 2 views
2

나는 작은 도전에 직면하고 있지만 시간이 흐르고 실제로 perl 사람이 아니기 때문에 어떤 도움도 환영합니다. 내가 가진 스크립트는 실행중인 프로세스를 모두 확인하고/tmp/error에 상태를 쓰는 스크립트이다. 그런 다음 외부 stmp를 통해 첨부 파일로 이메일을 보낼 펄 스크립트가 있지만 그/tmp/error를 취하는 코드가 뚫려있다. 이메일 본문에 첨부 할 필요가 없습니다. 이것이 내가 발견 한 것입니다.>이 파일을 첨부 파일로 보냅니다.Perl, 파일을 읽고 이메일 본문에 내용을 넣으십시오.

#!/usr/bin/perl 

use MIME::Lite; 

# Set this variable to your smtp server name 
my $ServerName = "smtp.comcast.net"; 

my $from_address = '[email protected]'; 
my $to_address = '[email protected]'; 
my $subject  = 'MIME Test: Text'; 
my $mime_type = 'text'; 
my $message_body = "Testing text in email.\n"; 

# Create the initial text of the message 
my $mime_msg = MIME::Lite->new(
    From => $from_address, 
    To => $to_address, 
    Subject => $subject, 
    Type => $mime_type, 
    Data => $message_body 
    ) 
    or die "Error creating MIME body: $!\n"; 


# Attach the text file 
my $filename = 'C:\tmp\test.txt'; 
my $recommended_filename = 'test.txt'; 
$mime_msg->attach(
    Type => 'application/text', 
    Path => $filename, 
    Filename => $recommended_filename 
    ) 
    or die "Error attaching text file: $!\n"; 

# encode body of message as a string so that we can pass it to Net::SMTP. 
my $message_body = $mime_msg->body_as_string(); 

# Let MIME::Lite handle the Net::SMTP details 
MIME::Lite->send('smtp', $ServerName); 
$mime_msg->send() or die "Error sending message: $!\n"; 

답변

1

이 바로 당신의 $message_body에 파일 내용을 추가 도와주세요?

my $message_body = "Testing text in email.\n"; 
{ 
    local $/ = undef; 
    open FILE, "file" or die "...: !$"; 
    $message_body .= <FILE>; 
    close FILE; 
} 

파일이 너무 크면주의하십시오.

+0

Thx, 열린 파일, "/tmp/yourmsg.txt"또는 죽기 "파일 열기 오류 : $!"; – user1821820

관련 문제