尝试通过Amazon SES发送HTML消息,邮件正在传递,但它不显示内容,如HTML页面,只是纯文本。
这是代码:
use Net::AWS::SES;
my $htmlBody = qq~<html>
<head>
<title>Title</title>
<link rel='stylesheet' href='http://example.com/css/animatedButton.css'>
<style>
html{
overflow:hidden;
}
@import url(http://fonts.googleapis.com/css?family=Ubuntu:400,700);
body {
/* IE10 Consumer Preview */
background-image: -ms-linear-gradient(bottom, #ffffff 0%, #e9f0f2 100%);
/* Mozilla Firefox */
background-image: -moz-linear-gradient(bottom, #ffffff 0%, #e9f0f2 100%);
/* Opera */
background-image: -o-linear-gradient(bottom, #ffffff 0%, #e9f0f2 100%);
/* Webkit (Safari/Chrome 10) */
background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, #ffffff), color-stop(1, #e9f0f2));
/* Webkit (Chrome 11+) */
background-image: -webkit-linear-gradient(bottom, #ffffff 0%, #e9f0f2 100%);
/* W3C Markup, IE10 Release Preview */
background-image: linear-gradient(to top, #ffffff 0%, #e9f0f2 100%);
#background: #3F53C4 no-repeat center top;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
}
</style>
</head>
<body>
<div class=\"wrapper\">
<div style=\"text-align: right; margin-top:2px; margin-right:2px;\"><img src=\"http://trackmyphones.com/ct/images/logos/celltracker.png\" width=\"50\" height=\"50\"/></div>
<p>
<div style=\"text-align: center; font-weight: bold;\">This is test msg from AWS SES</div>
</p>
<div style=\"text-align: left; margin-left:5%;margin-right: 5%; margin-bottom:2%; padding-left:2%; padding-right:2%; padding-top:2%; padding-bottom: 2%; background-color:#fae3e3;\">
<p>
This is test body
</p>
</div>
</body>
</html>
~;
my $ses = Net::AWS::SES->new(access_key => '...', secret_key => '...');
my $r = $ses->send(
From => 'to@example.com',
To => 'recepient@gmail.com',
Subject => 'Hello World from SES',
Body_html => "$htmlBody",
);
unless ( $r->is_success ) {
die "Could not deliver the message: " . $r->error_message;
}
printf("Sent successfully. MessageID: %s\n", $r->message_id);
上述代码返回成功,但收到的邮件将没有html中设置的背景颜色。
通过sendmail发送时,相同的html邮件效果非常好。
任何人都可以帮我解决缺失的问题吗?
编辑:
也使用以下MIME类型:
my $msg = MIME::Entity->build(
From => 'to@example.com',
To => 'from@gmail.com',
Subject => 'New Hello World from SES',
Data => ' ',
Type => 'text/html'
);
$msg->attach(
Data => "$mailContent",
Type => 'text/html'
);
上面也显示了文本而不是html,但是如果我将Data更改为指向正确显示的文件但是我必须将所有邮件写入文件然后发送邮件给SES:
$msg->attach(
Path => File::Spec->catfile( 'htmlContentMail.html' ),
Type => 'text/html'
);