use warnings;
use MIME::Lite;
use Net::SMTP;
### Adjust sender, recipient and your SMTP mailhost
my $from_address = '[email protected]';
my $to_address = '[email protected]';
my $mail_host = 'smtp.office365.com';
### Adjust subject and body message
my $subject = 'A message with 2 parts ...';
my $message_body = "Here's the attachment file(s) you wanted";
### Adjust the filenames
my $my_file_txt = 'C:\Users\Doni\Documents';
my $your_file_txt = 'test1.txt';
### 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 message part
$msg->attach (
Type => 'TEXT',
Data => $message_body
) or die "Error adding the text message part: $!\n";
### Add the TEXT file
$msg->attach (
Type => 'text',
Encoding => 'base64',
Path => $my_file_txt,
Filename => $your_file_txt,
Disposition => 'attachment'
) or die "Error adding file_text: $!\n";
##Send
MIME::Lite->send('smtp',$mail_host,SSL=>0,AuthUser=>'[email protected]',AuthPass=>'******',Debug=>1,Port=>587,Timeout=>60);
$msg->send;
命令的输出是:SMTP认证()命令不支持smtp.office365.com
##Here's the output
SMTP auth() command not supported on smtp.office365.com
如何解决这个问题?我坚持这一点。
你也可以使用Net :: SMTP(核心模块),并执行'$ mailer-> starttls() '建立连接后。少一个模块来安装。另外,您可以简单地执行'$ mailer-> data($ msg-> as_string)'并跳过'datesend'和'dataend'。 –
两个竖起大拇指给你bro @SteffenUllrich –