我正在尝试使用Email::MIMEs
(1.926)walk_parts
和body_set
.
更改存在,但是在发送邮件时,正在发送旧的/未更改的邮件文本。问题是:我必须做什么才能“激活”我的更改?
看:
use Email::MIME;
my $raw_message_text = q!Date: Wed, 26 Feb 2014 08:02:39 +0100
From: Me <me@example.com>
To: You <you@example.com>
Subject: test
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="------------010309070301040606000908"
This is a multi-part message in MIME format.
--------------010309070301040606000908
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
this is a test
--------------010309070301040606000908
Content-Type: text/plain;
name="file-to-attach.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="file-to-attach.txt"
dGV4dCBpbnNpZGUgYXR0YWNobWVudAoK
--------------010309070301040606000908--
!;
my $parsed_email = Email::MIME->new($raw_message_text);
$parsed_email->walk_parts(sub {
my ($part) = @_;
return if $part->subparts; # multipart
return unless ($part->content_type =~ /text\/plain.*charset=utf-8/i);
$part->body_set("new body text");
});
print "As you see the change is there:\n";
$parsed_email->walk_parts(sub {
my ($part) = @_;
return if $part->subparts; # multipart
my $body = $part->body;
print "Body:$body\n";
});
print "But the email object itself doesn't notice that:\n\n";
print $parsed_email->as_string;
这将首先显示更改后的正文,所以你看到它就在那里!但是当显示整个邮件时,会使用旧的正文。如果我只是使用发送电子邮件,也会发生同样的情况Email::Sender
。所以我想知道正确的用法body_set
是什么......