2017-10-16 3 views
0
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; 

die Ausgabe des Befehls lautet:SMTP-Auth() Befehl nicht auf smtp.office365.com unterstützt

##Here's the output 

SMTP auth() command not supported on smtp.office365.com 

, wie das Problem zu lösen? Ich bleibe dabei.

Antwort

0

vor allem habe ich

use Net::SMTP::TLS; 

nach MIME :: Lite-Codes, ich unten Mailer:

my $mailer = new Net::SMTP::TLS(
    "smtp.office365.com", 
    Hello =>  'smtp.office365.com', 
    Port =>  587, 
    User =>  '[email protected]', 
    Password=>  '******'); 
$mailer->mail('[email protected]'); 
$mailer->to('[email protected]'); 
$mailer->data; 
$mailer->datasend($msg->as_string); 
$mailer->dataend; 
$mailer->quit; 

Es arbeitete wie ein Charme!

+0

zu setzen Du könntest stattdessen auch das Net :: SMTP (Kernmodul) benutzen und einfach einen '$ mailer-> starttls() 'nach dem Herstellen der Verbindung. Ein weniger zu installierendes Modul. Sie könnten auch '$ mailer-> data ($ msg-> as_string)' eingeben und das 'datesend' und' dataend' überspringen. –

+0

zwei Daumen hoch für dich bro @SteffenUllrich –

1
MIME::Lite->send('smtp',$mail_host,SSL=>0,AuthUser=>...,Port=>587 ... 
            ^^^^^^ ^^^^^^ 

Sie versuchen, Authentifizierung ohne SSL zu verwenden. Dies wird von smtp.office365.com aus Sicherheitsgründen nicht unterstützt, wie im Handshake zu sehen ist. Die Antwort auf EHLO nach den ersten connect zeigt keine AUTH zur Verfügung:

<<< 220 LNXP265CA0010.outlook.office365.com Microsoft ESMTP MAIL Service ready at Mon, 16 Oct 2017 14:36:53 +0000 
>>> EHLO ... 
<<< 250-LNXP265CA0010.outlook.office365.com Hello ... 
<<< 250-SIZE 157286400 
<<< 250-PIPELINING 
<<< 250-DSN 
<<< 250-ENHANCEDSTATUSCODES 
<<< 250-STARTTLS 
<<< 250-8BITMIME 
<<< 250-BINARYMIME 
<<< 250-CHUNKING 
<<< 250 SMTPUTF8 

Nur wenn TLS AUTH Upgrade wird zur Verfügung:

>>> STARTTLS 
<<< 220 2.0.0 SMTP server ready 
>>> EHLO localhost.localdomain 
<<< 250-LNXP265CA0010.outlook.office365.com Hello ... 
<<< 250-SIZE 157286400 
<<< 250-PIPELINING 
<<< 250-DSN 
<<< 250-ENHANCEDSTATUSCODES 
<<< 250-AUTH LOGIN XOAUTH2   <<<<<<<<<<<<< HERE 
<<< 250-8BITMIME 
<<< 250-BINARYMIME 
<<< 250-CHUNKING 
<<< 250 SMTPUTF8 

Leider sieht es aus wie MIME :: Lite nicht die Verwendung unterstützen von Starts. Siehe die Antworten auf MIME::Lite - Cannot send mail [SMTP auth() command not supported on smtp.gmail.com] für Alternativen.

+0

Ich habe bereits meinen Code verfolgt und bearbeitet, um SSL => 1 hinzuzufügen und NET :: SMTP (3.10) zu verwenden, aber es hat immer noch nicht funktioniert. Was ist der beste Weg, um E-Mails an office365 zu senden? –

+0

@DoniAndriCahyono: 'SSL => 1' verwendet kein explizites TLS (d. H. Starttls), sondern implizites TLS. Um mich anzuführen: * "Leider sieht es so aus, als ob MIME :: Lite die Verwendung von starttls nicht unterstützt. Siehe die Antworten auf MIME :: Lite - Mail kann nicht gesendet werden .... für Alternativen *". –

+0

'MIME :: Lite' übergibt' SSL' nicht an 'Net :: SMTP' - siehe https://stackoverflow.com/questions/45588971/mimelite-3-030-netsmtp-with-smtps-port-465 – AnFi

0

Für mich ist die obige Lösung, mit Net::SMTP::TLS, für das Senden von E-Mails nicht MIME::Lite & Office365 mit arbeiten. Ich erhielt die folgende Fehlermeldung:

invalid SSL_version specified at /usr/share/perl5/IO/Socket/SSL.pm line 575. 

jedoch die Lösung gegeben hereNet::SMTPS verwenden, wie ein Charme.

Hier ist der Code-Schnipsel, die für mich gearbeitet:

my $email = MIME::Lite->new(From => 'John Doe <[email protected]>', 
          To  => $to, 
          Subject => $email_subject, 
          Type =>'multipart/related'); 

$email->attach(Type => 'text/html', 
       Data => $email_body); 

my $smtps = Net::SMTPS->new("smtp.office365.com", Port => 587, doSSL => 'starttls', SSL_version=>'TLSv1'); 

my $username = '[email protected]'; 
my $password = 'myc0mpl1c4t3dpa55w0rd'; 

$smtps->auth ($username, $password) or DIE("Nooooo..Could not authenticate with mail server!!\n"); 

$smtps->mail($username); 
$smtps->to($to); 
$smtps->data(); 
$smtps->datasend($email->as_string()); 
$smtps->dataend(); 
$smtps->quit; 

Hope this jemand hilft.

Verwandte Themen