2017-12-06 8 views
1

私は次のコードでのperl MIMEを介して送ら:: Liteは下記のメールを取得しようとしています:適切な解剖学

#!/usr/bin/perl5 -w 

############### 
sub email_it { 
############### 

use strict; 
use MIME::Lite; 

my ($recip, $body, $subj, $r_to, $ccs) = @_; 

my $msg = MIME::Lite->new(
     From  =>$r_to, 
     To  =>$recip, 
     Cc  =>$ccs, 
     Subject =>$subj, 
     Data => $body, 
    Type  =>'multipart/related', 
     ); 

$msg->attr('content-type.charset' => 'UTF-8'); 

my $user = $r_to; 
my $host = 'mail.somedomain.com'; 
my $reply; 

my ($user_id, $dom) = split /@/, $user; 

open CLAVE, "/usr/local/info/$user_id" or die "could not open " . $user_id . " " . $!; 

chomp (my ($userid, $pass, $lname) = <CLAVE>); 
close CLAVE; 

eval { 

    print "Executing in eval.\n"; 

    ($reply) = $msg->send('smtp','mail.somedomain.com', 
       AuthUser=>$user, AuthPass=>$pass); 

    print "reply was: " . $reply . "\n"; # only prints here if there was no problems 

}; 


if ([email protected]) { # msg->send failed 


    # we should also put this error in a log file 
    print "*********An error occurred ([email protected]), continuing\n"; 
    print "host was: " . $host . "\n"; 
    print "The user was: " . $user . "\n"; 
    print "With pss: " . $pass . "\n"; 
    print "user name from file was " . $r_to . "\n"; 
    print "We will try a different server\n"; 

    # try it again different smtp address 
    print "Trying: " . $host . "\n"; 
    sleep 3; 
    $host = 'mail.anotherdomain.com'; 

    eval { ($reply) = $msg->send('smtp', $host, 
        AuthUser=>$user, AuthPass=>$pass); }; 

} # end of if ([email protected]) { 


#$msg->send('smtp','smtp.bizmail.yahoo.com', AuthUser=>$user, AuthPass=>$pass); 

####################### 
} # end of sub email_it 
####################### 

# get contents of email body 
my @body; 
my $file = "BODY_OUT.FROM_TMPL"; 
open IN, '<', $file or warn "Could not open $file: $!\n"; 
while (my $line = <IN>) { 
    push(@body, $line); 
} 
close(IN) || die "Could not open $file: $!\n"; 

#make @body a scalar 
$body = "@body"; # make body a scalar  

#print "Here comes the body: $body\n"; 

email_it("myemail\@gmail.com", "Hope this works", $body, "sender\@somedomain.com", "richard\@somedomain.com"); 

私はそれが受信されますが、メールがHTMLとして表示されている送信する場合すべての電子メールクライアント。

<html> 
<head> 

    <title>Grid Master Template</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" /> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <!--[if !mso]><!--> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
    <!--<![endif]--> 

    <style type="text/css"> 

     table td {border: 1px solid #DDDDDD;} 

     .ReadMsgBody { width: 100%; background-color: #F1F1F1; } 
     .ExternalClass { width: 100%; background-color: #F1F1F1; } 
     body { width: 100%; background-color: #f6f6f6; margin: 0; padding: 0; -webkit-font-smoothing: antialiased; font-family: Arial, Times, serif } 
     table { border-collapse: collapse !important; mso-table-lspace: 0pt; mso-table-rspace: 0pt; } 
     *[class*="mobileOn"] { display: none !important; max-height: none !important; } 

     @-ms-viewport{ width: device-width; } 

     @media only screen and (max-width: 639px){ 
     .wrapper{ width:100%; padding: 0 !important; } 
     }  
     @media only screen and (max-width: 480px){ 
     .centerClass{ margin:0 auto !important; } 
     .imgClass{width:100% !important; height:auto;}  
     .wrapper{ width:320px; padding: 0 !important; }  
     .container{ width:300px; padding: 0 !important; } 
     .mobile{ width:300px; display:block; padding: 0 !important; text-align:center; } 
     .mobile50{ width:300px; padding: 0 !important; text-align:center; } 
     *[class="mobileOff"] { width: 0px !important; display: none !important; } 
     *[class*="mobileOn"] { display: block !important; max-height: none !important; } 
     } 

    </style> 

    <!--[if gte mso 15]> 
    <style type="text/css"> 
     table { font-size:1px; line-height:0; mso-margin-top-alt:1px;mso-line-height-rule: exactly; } 
     * { mso-line-height-rule: exactly; } 
    </style> 
    <![endif]-->  

</head> 
<body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0" yahoo="fix" style="background-color:#F2F2F2; font-family:Arial,serif;margin:0;padding:0;min-width: 100%; -webkit-text-size-adjust:none;-ms-text-size-adjust:none;"> 

    <!--[if !mso]><!-- --> 
    <img style="min-width:640px;display:block;margin:0;padding:0" class="mobileOff" width="640" height="1" src="https://s14.postimg.org/7139vfhzx/spacer.gif"> 
    <!--<![endif]--> 

    <!-- Start Background --> 
    <table width="100%" cellpadding="0" cellspacing="0" border="0"> 
     <tr> 
      <td width="100%" valign="top" align="center"> 

<!-- Start Wrapper ----------------------------------------- GRID ONE --> 

      <!-- Start Wrapper ----------------------------------------- GRID ONE --> 
<table width="640" cellpadding="0" cellspacing="0" border="0" class="wrapper" bgcolor="#FFFFFF"> 
    <tr> 
     <td height="10" style="font-size:10px; line-height:10px;"> </td><!-- Spacer --> 
    </tr> 
    <tr> 
     <td align="center"> 
      <!-- Start Container --> 
      <table width="600" cellpadding="0" cellspacing="0" border="0" class="container"> 
       <tr> 
        <td width="600" class="mobile" style="font-size:12px; line-height:18px;"> 
         <div align="center"> 
      <h2>RUSH LOGISTICS, INC - 888-448-7874 - rushlogistics.com/movie</h2> 
      <h2><<< We Deliver Reliability >>></h2> 
       </div> 
        </td> 
       </tr> 
      </table> 
      <!-- Start Container -->     

     </td> 
    </tr> 
    <tr> 
     <td height="10" style="font-size:10px; line-height:10px;"> </td><!-- Spacer --> 
    </tr>       
</table> 
<!-- End Wrapper --> 
<!-- Start Wrapper ----------------------------------------- GRID ONE --> 
<table width="640" cellpadding="0" cellspacing="0" border="0" class="wrapper" bgcolor="#FFFFFF"> 
    <tr> 
     <td height="10" style="font-size:10px; line-height:10px;"> </td><!-- Spacer --> 
    </tr> 
    <tr> 
     <td align="center"> 
      <!-- Start Container --> 
      <table width="600" cellpadding="0" cellspacing="0" border="0" class="container"> 
       <tr> 
        <td width="600" class="mobile" style="font-size:12px; line-height:18px;"> 
         <p><strong>CUSTOMER RATE QUOTATION:</strong></p> 
       <p> Attention: Fulgencio Salgado</p> 
       <pre>Cosmo Films Quote No: 0 
                Date: 
       </td> 
       </tr> 
      </table> 
      <!-- Start Container -->     
     </td> 
    </tr> 
    <tr> 
     <td height="10" style="font-size:10px; line-height:10px;"> </td><!-- Spacer --> 
    </tr>       
</table> 
<!-- End Wrapper --> 

    <!-- Start Wrapper --> 
    <table width="640" cellpadding="0" cellspacing="0" border="0" class="wrapper" bgcolor="#FFFFFF"> 
     <tr> 
      <td height="10" style="font-size:10px; line-height:10px;"> </td> <!-- Spacer --> 
     </tr> 
     <tr> 
      <td align="center"> 

       <!-- Start Container --> 
       <table width="600" cellpadding="0" cellspacing="0" border="0" class="container"> 
        <tr> 
         <td width="200" class="mobile" style="font-size:12px; line-height:18px;"> 
         <h3>Origin</h3> 
      </td> 
         <td width="200" class="mobile" style="font-size:12px; line-height:18px;"> 
         <h3>Destination</h3> 
         </td> 
         <td width="200" class="mobile" style="font-size:12px; line-height:18px;"> 
         <h3>Base Price</h3> 
         </td>      
        </tr> 
       </table> 
       <!-- Start Container -->     

      </td> 
     </tr> 
     <tr> 
      <td height="10" style="font-size:10px; line-height:10px;"> </td> <!-- Spacer --> 
     </tr>       
    </table> 
    <!-- End Wrapper --> 

    <!-- Start Wrapper --> 
    <table width="640" cellpadding="0" cellspacing="0" border="0" class="wrapper" bgcolor="#FFFFFF"> 
     <tr> 
      <td height="10" style="font-size:10px; line-height:10px;"> </td> <!-- Spacer --> 
     </tr> 
     <tr> 
      <td align="center"> 

       <!-- Start Container --> 
       <table width="600" cellpadding="0" cellspacing="0" border="0" class="container"> 
       <tr> 
        <td width="200" class="mobile" style="font-size:12px; line-height:18px;"> 
        Addison, IL 
        </td> 
        <td width="200" class="mobile" style="font-size:12px; line-height:18px;"> 
        Whitestown, IN 
        </td> 
        <td width="200" class="mobile" style="font-size:12px; line-height:18px;"> 
        695.00 
        </td>      
        </tr> 
       </table> 
       <!-- Start Container -->     

      </td> 
     </tr> 
     <tr> 
      <td height="10" style="font-size:10px; line-height:10px;"> </td> <!-- Spacer --> 
     </tr>       
    </table> 
    <!-- End Wrapper --> 

    <!-- Start Wrapper --> 
<table width="640" cellpadding="0" cellspacing="0" border="0" class="wrapper" bgcolor="#FFFFFF"> 
    <tr> 
     <td height="10" style="font-size:10px; line-height:10px;"> </td><!-- Spacer --> 
    </tr> 
    <tr> 
     <td align="center"> 

      <!-- Start Container --> 
      <table width="600" cellpadding="0" cellspacing="0" border="0" class="container"> 
       <tr> 
        <td width="600" class="mobile" style="font-size:12px; line-height:18px;"> 
         <strong>* Plus fuel sur charge (currently 16.5%) TOTAL:</strong> 
      <p>Thank you for the opportunity to quote your business.</p> 
      <p> 
       Sincerely, 
      </p> 
      <p> 
       Richard Reina 
      <p/> 
      <p> 
       Watch our 3 minute movie and learn about the Rush Logistics difference. 
       rushlogistics.com/movie 
      </p> 
      <p> 
       *Rate not valid for a collect shipment to a non current Rush Logistics customer 
      </p> 
      </td> 
       </tr> 
      </table> 
      <!-- Start Container -->     

     </td> 
    </tr> 
    <tr> 
     <td height="10" style="font-size:10px; line-height:10px;"> </td><!-- Spacer --> 
    </tr>       
</table> 
<!-- End Wrapper --> 



      </td> 
     </tr> 
    </table> 
    <!-- End Background --> 

</body> 
</html> 

MIME :: Liteを使用する前に、より簡単な電子メールを送信しました。これは、以下のようなものです。これらは、視覚的に正しく表示されます。私はそれが非常に基本的なものだと思っています。私は行方不明ですが、何が分かりませんか?

<hr/> 
<pre> 
      Richard Reina 1808 W Buckingham. Chicago, IL 60657 

</pre> 
<hr/> 

<p><strong>ANNOINCEMENT:        </strong> 

</p><p> Attention: Residents 
</p> 

</p>Building water will be shut off from 9am to 10:30am</p> 
<p> Thank you for the opportunity to quote your business. 

</p><p> Sincerely, 

</p><p> Richard Reina 

</p> 
+0

最後に電子メールを送信して以来、MIME :: Liteライブラリが変更されていますか?それが私がチェックする最初のものだろう。また、問題を再現できる小さなコードセットを分離することをお勧めします。 –

答えて

0

は、最初の行に<!DOCTYPE html>を追加することを検討してください。

DOCTYPEプリアンブルについては、http://w3c.github.io/html/syntax.html#the-doctypeを参照してください。

また、http://search.cpan.org/~rjbs/MIME-Lite-3.030/lib/MIME/Lite.pmによれば、MIME :: Liteはもはや使用することをお勧めしません。

+0

同じ結果が、これは、電子メールの上部に表示され受け入れる:<!DOCTYPE HTML> – gatorreina

+0

あなたはそれであなたを助けることができるように私たちのために使っているコードを表示する必要があります。 – Borodin

+0

SMTPメッセージのデータに 'Content-type'ヘッダーを追加する必要がありますが、その方法はコードの構造によって異なります。 'attach'を使用している場合は、' Type => 'text/html''パラメータを呼び出しに追加するだけです。 – Borodin

関連する問題