473,591 Members | 2,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Thanks in advanced.
Aug 31 '10 #1
9 4530
988 Recognized Expert Contributor
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.


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
22 New Member
Thanks Oralloy,

I added another text template called test.txt.tt,
Expand|Select|Wrap|Line Numbers
  1. Dear [% sender_name %],
  3. This is to confirm your order of $ [% amount %] gift voucher from Evergreens Day Spa.
  5. Status: unpaid.
  7. Thank you!
  9. Yours Sincerely
  10. Evergreens Day Spa Team
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
Aug 31 '10 #3
988 Recognized Expert Contributor

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_testfi le($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
22 New Member
Hi Oralloy,

I use
Expand|Select|Wrap|Line Numbers
  1. my $raw_message = $msg->as_string;
  2. print "$raw_message";
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
988 Recognized Expert Contributor

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
  3. Dear EricLin,
  5. This is to confirm your order of $ 50 gift voucher from Evergreens Day Spa.
  7. Status: unpaid.
  9. Thank you!
  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
988 Recognized Expert Contributor

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?

Aug 31 '10 #7
22 New Member
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
988 Recognized Expert Contributor

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.

Sep 7 '10 #9
1 New Member
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("conten t-type" => "multipart/mixed");

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

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

Similar topics

by: ywang123 | last post by:
Hi There, I am using MIME::Lite::TT::HTML Perl module to send an HTML based email. HTML file contains a header image and footer image and the content within. When I send an email using this module, I can see on the mail client only the text content and not the header and footer images. - I am sure the images are in the same path as the html files is and as well I tried giving absolute path of images in the HTML file as well. But nothing...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.