469,306 Members | 2,504 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

MIME::Lite::TT::HTML, send email twice

Hi Code Masters,

It seems there is not so much documentation around this "MIME::Lite::TT::HTML" module.

I have a Perl script used to send confirmation emails to customers when they have ordered a gift voucher, part of the script is:
Expand|Select|Wrap|Line Numbers
  1. my %params;
  2.  
  3. $params{sender_name} = "$sender_first_name"."$sender_last_name";
  4. $params{amount}  = $gift_amount;
  5.  
  6. my %options;
  7. $options{INCLUDE_PATH} = 'templates/';
  8.  
  9. my $msg = MIME::Lite::TT::HTML->new(
  10.             From        =>  'test@test.com',
  11.             To          =>  $email,
  12.             Subject     =>  'Gift Voucher From Evergreens Day Spa',
  13.             Template    =>  {
  14.                                 html    =>  'test.html.tt',
  15.                             },
  16.             TmplOptions =>  \%options,
  17.             TmplParams  =>  \%params,
  18. );
  19.  
  20. # Set our content type properly
  21. $msg->attr("content-type"  => "multipart/mixed");
  22.  
  23. my $path_to_attachment = "vouchers/$ref.pdf";
  24.  
  25. $msg->attach(
  26.             Type        =>  'application/pdf',
  27.             Path        =>  $path_to_attachment,
  28.             Filename    =>  'Gift Voucher.pdf',
  29.             Disposition =>  'attachment'
  30. );
  31.  
  32. $msg->send;
  33.  
Sample codes in test.html.tt are:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <body>
  4.  
  5. <p>Dear [% sender_name %],</p> 
  6.  
  7. <p>This is to confirm your order of $ [% amount %] gift voucher from Evergreens Day Spa. </p>
  8.  
  9. <p>Status: unpaid.</p>
  10.  
  11. <p>Thank you!</p>
  12.  
  13. <p>Yours Sincerely
  14. Evergreens Day Spa Team </p>
  15.  
  16. </body>
  17.  
  18. </html>
  19.  
  20.  
But when it executed, I got the following email:
Expand|Select|Wrap|Line Numbers
  1. Dear EricLin,
  2.  
  3.   This is to confirm your order of $ 300 gift voucher from Evergreens
  4.   Day Spa.
  5.  
  6.   Status: unpaid.
  7.  
  8.   Thank you!
  9.  
  10.   Yours Sincerely Evergreens Day Spa Team
  11.  
  12.  
  13. Dear EricLin,
  14.  
  15. This is to confirm your order of $ 300 gift voucher from Evergreens Day Spa.
  16.  
  17. Status: unpaid.
  18.  
  19. Thank you!
  20.  
  21. Yours Sincerely Evergreens Day Spa Team
  22.  
  23.  
Any idea? What I really want is a nice formatted HTML email message and attachment.

Thanks in advanced.
Aug 31 '10 #1
9 4115
Oralloy
983 Expert 512MB
It looks like it mapped your HTML code into text using a fairly transparent representation.

Take a look at this CPAN page.

Notice that he calls out a text template as well as an HTML template.

I don't know if you're aware, but the basic protocol for email is to have a text-only version of the HTML version. That way viewers are free to present the appropriate view to the user. Probably something you've not run into much, but for those of us who grew up with text-only interfaces, it's how we wanted to read our mail. Reading HTML to figure out what was said in fancy messages was quite ugly some times.

Give that a try and let me know what happens.

Cheers!
Oralloy

p.s. I just looked at the source for the module. If you do not supply a text template, it uses the HTML template in its place. I suspect that this is causing your problem with duplication. What I'm not certain of is why the message wasn't properly packaged. Oh the other hand, it might be a email-reader bug that you're seeing.

p.p.s. Can you look at the true body of the mail message? If so, that should tell you exactly what is being constructed.
Aug 31 '10 #2
Thanks Oralloy,

I added another text template called test.txt.tt,
Expand|Select|Wrap|Line Numbers
  1. Dear [% sender_name %],
  2.  
  3. This is to confirm your order of $ [% amount %] gift voucher from Evergreens Day Spa.
  4.  
  5. Status: unpaid.
  6.  
  7. Thank you!
  8.  
  9. Yours Sincerely
  10. Evergreens Day Spa Team
  11.  
and called it with the html one, but I still received two exact same message in one email.

I suppose it is a bug? What module do you use normally for this kind of situation?

Best Regards
Eric
Aug 31 '10 #3
Oralloy
983 Expert 512MB
Eric,

Sorry I missed your post back.

Frankly, I've only had to do fancy emails once, and I think I did them using the bare MIME::Lite module at the time.

Did you change your driver to reflect the addition of the text module in the Template hash?

Also, were you able to look at the raw body of the email you sent? You might be able to extract it from the msg object.

Ok, I looked. You can use $msg->send_by_testfile($filename) to look at your message body. Will you do that and then upload it?

Also, try inserting this in the arguments, when you create the message:
Expand|Select|Wrap|Line Numbers
  1.  Type    => 'multipart/mixed' 
Aug 31 '10 #4
Hi Oralloy,

I use
Expand|Select|Wrap|Line Numbers
  1. my $raw_message = $msg->as_string;
  2. print "$raw_message";
  3.  
to display the message body, I have attached the file, can you please have a look at here .

P.S. What module you used to send normal email? I used to have mail:sendmail.
Aug 31 '10 #5
Oralloy
983 Expert 512MB
Eric,

When I look at the file using notepad on my PC, I notice that many of the headers do not have line breaks between them. I don't think that's correct. Do you have vi available?

What I see is on lines of:
Expand|Select|Wrap|Line Numbers
  1. MIME-Version: 1.0 Content-Transfer-Encoding: binary Content-Type: multipart/mixed; boundary="_----------=_1283226224255410" X-Mailer: MIME::Lite 3.027 (F2.74; T1.28; A2.06; B3.07; Q3.07) Subject: =?US-ASCII?B?R2lmdCBWb3VjaGVyIEZyb20gRXZlcmdyZWVucyBEYXkgU3Bh?= Date: Tue, 31 Aug 2010 03:43:44 -0000 To: nzsquall@gmail.com From: info@evergreensdayspa.co.nz This is a multi-part message in MIME format. --_----------=_1283226224255410 Content-Disposition: inline Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Dear EricLin, This is to confirm your order of $ 50 gift voucher from Evergreens Day Spa. Status: unpaid. Thank you! Yours Sincerely Evergreens Day Spa Team --_----------=_1283226224255410 Content-Disposition: inline Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii
  2.  
  3. Dear EricLin,
  4.  
  5. This is to confirm your order of $ 50 gift voucher from Evergreens Day Spa.
  6.  
  7. Status: unpaid.
  8.  
  9. Thank you!
  10.  
  11. Yours Sincerely Evergreens Day Spa Team
  12. --_----------=_1283226224255410 Content-Disposition: attachment; filename="Gift Voucher.pdf" Content-Transfer-Encoding: base64 Content-Type: application/pdf; name="Gift Voucher.pdf" JVBERi0xLjQKJcfs86IKMSAwIG9iaiA8PCAvVHlwZSAvQ2F0YWxvZyAvVmll d2VyUHJlZmVyZW5jZXMgPDwgL05vbkZ1bGxTY3JlZW5QYWdlTW9kZSAvVXNl 
Which really bothers me.

At this point, I'd spend a little time reading into the module and figuring out why the line breaks between the headers are being malformed.

@Nzsquall, thanks for putting in the link. I appreciate it.
Aug 31 '10 #6
Oralloy
983 Expert 512MB
Eric,

That's interesting - the two gift voucher content lines that I included in my output listing were grafted onto the headers for the attachment. I'm wondering if there's a problem with line delimiters, which is confusing things.

Also, I see that the text and HTML renderings are both tagged as "Content-Disposition: inline". I wonder if that's why you may be having problems.

Lastly, I do not see the HTML tags from your template anywhere in the file. Did you change your invocation at all?

Cheers!
Aug 31 '10 #7
Hi Oralloy,

I am sorry about the late reply.

I did have the html tag in my test.html.tt file. Anyway, I don't use this module any more. Now I use MIME::Lite instead, and problem solved itself. How strange it that!

I really appreciate your help, many thanks!
Sep 4 '10 #8
Oralloy
983 Expert 512MB
Nzsquall,

Glad I could help. It's been a while since I've done Perl, and the one thing I've noticed is that I did do a lot of debugging on modules. It's not that the authors didn't put together good software, but rather that I stressed the modules that they'd published.

At least you have your answer.

Luck!
Oralloy
Sep 7 '10 #9
I was having the same issue: two copies of the text within the email, one as plain text and one as HTML, as well as an attachment. (using MIME::Lite::TT:HTML.) Posting my very simple solution here after much struggle:

I removed the line

$msg->attr("content-type" => "multipart/mixed");

Bam, problem solved, it only shows one version of the text.
Jan 8 '13 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.