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;
la sortie de la commande est:auth SMTP() sur smtp.office365.com
##Here's the output
SMTP auth() command not supported on smtp.office365.com
Comment résoudre ce problème? Je suis coincé avec ça.
Vous pourriez plutôt utiliser aussi le Net :: SMTP (module de base) et juste faire un '$ mailer-> starttls() 'après avoir établi la connexion. Un module de moins à installer. En outre, vous pouvez simplement faire '$ mailer-> data ($ msg-> as_string)' et ignorer 'datesend' et' dataend'. –
deux bravo pour vous bro @SteffenUllrich –