在Perl sendmail中,为什么有时我的Image附件损坏了?

问题描述 投票:0回答:1

我打算在Net :: SMTP中重写它,但是现在我需要一个备份子程序,它不会“使用”太多,所以;

该代码可以正常工作并发送电子邮件,当在大多数电子邮件服务(Godaddy,ProtonMail)中收到时,我会得到完整的图像,但是在另一个(34SP)电子邮件服务中,我只会得到图像的上半部分。

my $msg = "From: John <$sender>
To: bob <$recipient>
Subject: $subject
MIME-Version: 1.0     
Content-Type: multipart/mixed; boundary=\"BOUNDARY\"

--BOUNDARY        
Content-Type: multipart/alternative; boundary=\"MSGBOUNDARY\"

--MSGBOUNDARY
Content-Type: text/html; charset=iso-8859-1
Content-Disposition: inline

<html><body>Hello, World<br><img src=\"cid:hello\"></body></html>
--MSGBOUNDARY
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline

Hello, World,[you're missing an image here]
--MSGBOUNDARY--
--BOUNDARY
Content-Type: image/jpeg
Content-Disposition: inline; filename=\"hello.jpg\"
Content-Transfer-Encoding: base64
Content-Id: <hello>

$jpgg 
--BOUNDARY--";

open MAIL, "| $sendmail -t" 
        or die "Couldn't pipe to $sendmail";
print MAIL $msg;
close MAIL;

我已经通过从另一个位置发送第一个附件来测试了34SP电子邮件服务,并且可以很好地接收它,因此它一定是代码问题。如果有人看到我做错了什么,我将不胜感激。

EDIT(1);根据Polar Bears的建议,我已经编辑了代码以方便阅读,我已经测试了此版本,仍然遇到相同的问题。

perl email sendmail attachment corruption
1个回答
-1
投票

只是建议将代码更改为以下形式

my $msg = "
From: John <$sender>
To: bob <$recipient>
Subject: $subject
MIME-Version: 1.0     
Content-Type: multipart/mixed; boundary=\"BOUNDARY\"

--BOUNDARY        
Content-Type: multipart/alternative; boundary=\"MSGBOUNDARY\"

--MSGBOUNDARY
Content-Type: text/html; charset=iso-8859-1
Content-Disposition: inline

<html><body>Hello, World<br><img src=\"cid:hello\"></body></html>
--MSGBOUNDARY
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Hello, World,[you're missing an image here]
--MSGBOUNDARY--
--BOUNDARY
Content-Type: image/jpeg
Content-Disposition: inline; filename=\"hello.jpg\"
Content-Transfer-Encoding: base64
Content-Id: <hello>

$jpgg
--BOUNDARY--
";

open MAIL, "| $sendmail -t" 
        or die "Couldn't pipe to $sendmail";

print MAIL $msg;

close MAIL;
© www.soinside.com 2019 - 2024. All rights reserved.