
06-18-07, 02:08 AM
|
|
Wannabe Coder
|
|
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Attachement help needed
I need to attached some file (like: pdf, doc, excel, image) within a email automatically, when a new user register for some service. This registration script on CGI and new user after successful registration got a text email, generated by this script but we would like to add one feature that depending on service he choose on the time of registration, he will; get a sample service details along with that thank you email.
If needed we will upload these files on the server on particular folder. Script need to attaché this files into email depend on service chose and send as an attachment.
Anyone have any idea how do I do this?
Thanks.
|

06-18-07, 09:20 AM
|
|
Wannabe Coder
|
|
Join Date: Aug 2006
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
using the MIME::Lite module will make most of your emailing requirements much easier, including adding attachements.
|

06-19-07, 03:15 AM
|
|
Wannabe Coder
|
|
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Drunken Perl Coder!
i have used this code and try to execute it but working CHMOD is 755 and filename is sendmail2.pl but its giving 500 internal server error.
perl Code:
#!/usr/bin/perl -w use MIME::Lite; ### Create a new single-part message, to send a GIF file: $msg = MIME::Lite->new( From =>'sujata@k****ij.com', To =>'sujata_atkcs@yahoo.com', Cc =>'sujata_ghosh@hotmail.com', Subject =>'Helloooooo, nurse!', Type =>'image/gif', Encoding =>'base64', Path =>'/home/k****ijc/www/com/casestudy1.gif' ); $msg->send; # send via default
i have got this code from here: http://search.cpan.org/dist/MIME-Lit...mages_included!
i have checked that MIME::Lite is installed on our perl server.
Please help!
Thanks.
Last edited by UnrealEd; 06-19-07 at 03:20 AM.
Reason: please use the [highlight=perl] tag when posting perl code
|

06-19-07, 03:35 AM
|
|
Wannabe Coder
|
|
Join Date: Aug 2006
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Any perl code run as a CGI will return a 500 internal server error if you don't print an http header. I assume you are just testing to see if MIME::Lite works, if so, just print a header and a short message at the end of the script.
perl Code:
#!/usr/bin/perl -w use MIME::Lite; ### Create a new single-part message, to send a GIF file: $msg = MIME::Lite->new( From =>'sujata@k****ij.com', To =>'sujata_atkcs@yahoo.com', Cc =>'sujata_ghosh@hotmail.com', Subject =>'Helloooooo, nurse!', Type =>'image/gif', Encoding =>'base64', Path =>'/home/k****ijc/www/com/casestudy1.gif' ); $msg->send; # send via default print "Content-type: text/html\n\n";
Last edited by Nico; 06-19-07 at 04:18 AM.
|

06-19-07, 07:03 AM
|
|
Wannabe Coder
|
|
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks a lot!
yes i am getting email but as i have not added anything to display on the screen so i was getting error message. now it's working. now i need to know some more info,
1) the email script i was using which take data from diffent variable as follows:
perl Code:
sub send_mail{ my @boundaryv = (0..9, 'A'..'F'); $PREF{'FOOTER'} =~ s/\\n/\n/g; $| = 1; my @boundaryv = (0..9, 'A'..'F'); for (my $i = 0; $i++ < 24;) { $boundary .= $boundaryv[rand(@boundaryv)]; } #foreach my $file (@files) #{ do { push @problem, "$file"; next; } if !-r "$upload_dir/$file"; # checks the existence and readability #--------------------------------------------------- Obtain content-type of file ($ext) = $file =~ m,\. (& #91;^\.]*)$,; my $fext = $mime{$ext}; #--------------------------------------------------- Generate multipart boundary for (my $i = 0; $i++ < 24;) { $boundary .= $boundaryv[rand(@boundaryv)]; } #--------------------------------------------------- Send attatchments etc... open MAIL, "| $mail_prog -finrreturn\@k****ij.com" || die "I was not able to open the mail program<BR>contact the server's technical administrator.<BR><BR>If this is not admin, please let him/her<BR> know about this problem."; print MAIL "From: Vikram Murarka <vikram\@k****ij.com>\n"; print MAIL "Return-Path: Vikram Murarka <vikram\@k****ij.com>\n"; print MAIL "Reply-To: Vikram Murarka <vikram\@k****ij.com>\n"; print MAIL "X-Mailer: Custom-CGI: Web Mailer v1.02\n"; print MAIL "MIME-Version: 1.0\n"; print MAIL "Subject: $INPUT{'subject'}\n"; print MAIL "Content-Type: multipart/mixed; boundary=\"------------$boundary\"\n"; print MAIL "This is a multi-part message in MIME format.\n"; print MAIL "--------------$boundary\n"; print MAIL "Content-Type: text/plain; charset=us-ascii\n"; print MAIL "Content-Transfer-Encoding: 7bit\n\n"; print MAIL "$subject \n"; if (!$edition) { $edition = ""; } else { print MAIL "$edition \n"; } if ((!$inr1) && (!$inrm1)) { $inr1 = ""; $inrm1 = ""; } else { } if ((!$fwd1) && (!$fwdm1)) { $fwd1 = ""; $fwd1 = ""; } else { print MAIL "$fwdm1\n\n\n"; } if ((!$strategy1) && (!$strategym1)) { $strategy1 = ""; $strategym1 = ""; print MAIL "$strategym1"; } else { print MAIL "$strategy1\n"; print MAIL "$strategym1\n\n"; } if ((!$eurrs1) && (!$eurrsm1)) { $eurrs1 = ""; $eurrsm1 = ""; } else { print MAIL "$eurrsmail2\n\n"; print MAIL "$eurrsmmail2\n\n\n"; } } sub encode_base64 #($) { my ($res, $eol, $padding) = ("", "\n", undef); while (($_[0] =~ /(.{1,45})/gs)) { } $res =~ tr#` -_#AA-Za-z0-9+/#; # ` help emacs $padding = (3 - length($_& #91;0]) % 3) % 3; # fix padding at the end $res =~ s#.{$padding}$#'=' x $padding#e if $padding; # pad eoedv data with ='s $res =~ s#(.{1,76})#$1$eol#g if (length $eol); # lines of at least 76 characters }
now how i will converted into it:
perl Code:
#!/usr/bin/perl -w use MIME::Lite; my $message_body = "Here's the attachment file(s) you wanted<br><b>h</b>"; ### Create a new single-part message, to send a GIF file: $msg = MIME::Lite->new( From =>'sujata@k****ij.com', To =>'sujata_atkcs@yahoo.com', Cc =>'sujata_ghosh@hotmail.com, [EMAIL="sujata_ghosh1@rediffmail.com'"]sujata_ghosh1@rediffmail.com'[/EMAIL], Subject =>'Helloooooo, nurse!', Type =>'application/octet-stream', Encoding =>'base64', Path =>'/home/k****ijc/www/temp/inr rates.xls' ); $msg->attach ( Type => 'text/html', Data => $message_body ) or die "Error adding the text message part: $!\n"; $msg->send; # send via default print "Content-type: text/html\n\n"; print "Message sent";
2) i am using a script which take data from form and make HTML page and send HTML mail using same email script and additional code only i change the 'text/html' part this email message consist of images which appears with email body message, but it is not showing into email. as we are using this code to display it on HTMl page: (<img src="full path of the file">) how i will use the same to display it on proper place in the email body with text?
Thanks once again.
Last edited by UnrealEd; 06-19-07 at 07:22 AM.
Reason: please use the correct syntax highlighters!!
|

06-19-07, 02:27 PM
|
|
Wannabe Coder
|
|
Join Date: Aug 2006
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Do you want to send an html encoded email or send an attachment? I'm confused. I think if you read the MIME::Lite documentation more you will figure out whatever it is you are trying to do. It is one of the better documented modules and has many examples.
|

06-20-07, 12:14 AM
|
|
Wannabe Coder
|
|
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I need both........... i need to send text and html email with attachement also i need to send HTML email with images with body text, except from that i need know how do i refer these portion of my old email code into MIME::Lite??
Code:
print MAIL "$subject \n";
if (!$edition)
{
$edition = "";
print MAIL "$edition";
}
else
{
print MAIL "$edition \n";
}
print MAIL "$time \n\n";
if ((!$inr1) && (!$inrm1))
{
$inr1 = "";
$inrm1 = "";
print MAIL "$inr1";
print MAIL "$inrm1";
}
else
{
print MAIL "$inr1\n";
print MAIL "$inrm1\n\n";
}
if ((!$fwd1) && (!$fwdm1))
{
$fwd1 = "";
$fwd1 = "";
print MAIL "$fwd1";
print MAIL "$fwdm1";
}
else
{
print MAIL "$fwd1\n";
print MAIL "$fwdm1\n\n\n";
}
if ((!$strategy1) && (!$strategym1))
{
$strategy1 = "";
$strategym1 = "";
print MAIL "$strategy1";
print MAIL "$strategym1";
}
else
{
print MAIL "$strategy1\n";
print MAIL "$strategym1\n\n";
}
if ((!$eurrs1) && (!$eurrsm1))
{
$eurrs1 = "";
$eurrsm1 = "";
print MAIL "$eurrs1";
print MAIL "$eurrsm1";
}
else
{
print MAIL "$eurrsmail2\n\n";
print MAIL "$eurrsmmail2\n\n\n";
}
print MAIL "$dis\n\n";
print MAIL "\n";
and the MIME::Lite code is:
Code:
#!/usr/bin/perl -w
use MIME::Lite;
my $message_body = "Here's the attachment file(s) you wanted<br><b>h</b>";
### Create a new single-part message, to send a GIF file:
$msg = MIME::Lite->new(
From =>'sujata@k****ij.com',
To =>'sujata_atkcs@yahoo.com',
Cc =>'sujata_ghosh@hotmail.com, sujata_ghosh1@rediffmail.com',
Subject =>'Helloooooo, nurse!',
Type =>'application/octet-stream',
Encoding =>'base64',
Path =>'/home/k****ijc/www/temp/inr rates.xls'
);
$msg->attach (
Type => 'text/html',
Data => $message_body
) or die "Error adding the text message part: $!\n";
$msg->send; # send via default
print "Content-type: text/html\n\n";
print "Message sent";
thanks for your help and responce
|

06-20-07, 03:17 AM
|
|
Wannabe Coder
|
|
Join Date: Aug 2006
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
perl Code:
my $message = "$subject \n"; if (!$edition) { $edition = ""; $message .= $edition; } else { $message .= "$edition \n"; } $message .= "$time \n\n"; if ((!$inr1) && (!$inrm1)) { $inr1 = ""; $inrm1 = ""; $message .= $inr1; $message .= $inrm1; } else { $message .= "$inr1\n"; $message .= "$inrm1\n\n"; } if ((!$fwd1) && (!$fwdm1)) { $fwd1 = ""; $fwd1 = ""; $message .= $fwd1; $message .= $fwdm1; } else { $message .= "$fwd1\n"; $message .= "$fwdm1\n\n\n"; } if ((!$strategy1) && (!$strategym1)) { $strategy1 = ""; $strategym1 = ""; $message .= $strategy1; $message .= $strategym1; } else { $message .= "$strategy1\n"; $message .= "$strategym1\n\n"; } if ((!$eurrs1) && (!$eurrsm1)) { $eurrs1 = ""; $eurrsm1 = ""; $message .= $eurrs1; $message .= $eurrsm1; } else { $message .= "$eurrsmail2\n\n"; $message .= "$eurrsmmail2\n\n\n"; } $message .= "$dis\n\n"; $message .= "\n";
now use $message where ever you need to with your new code.
Last edited by UnrealEd; 06-20-07 at 05:17 AM.
Reason: please use the [highlight=perl] tag when posting perl code
|

06-20-07, 07:13 AM
|
|
Wannabe Coder
|
|
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks a lot!
i have used and it working.
return path of the email is not working now:
Code:
$msg = MIME::Lite->new(
From =>'Vikram Murarka <vikram@k****ij.com>',
To => $em,
Return-path =>'inrreturn@k****ij.com',
Reply-To =>'Vikram Murarka <vikram@k****ij.com>',
Subject => $subject,
Type =>'text',
Data => $message
);
$msg->attach (
Type => 'application/msword',
Encoding => 'base64',
Path => '/home/k****ijc/www/com/colour of money 26may07.doc'
) or die "Error adding the text message part: $!\n";
$msg->send; # send via default
i used it on my older code like that: " -finrreturn\@k****ij.com"
Code:
open MAIL, "| $mail_prog -finrreturn\@k****ij.com" || die "I was not able to open the mail program<BR>contact the server's technical administrator.<BR><BR>If this is not admin, please let him/her<BR> know about this problem.";
print MAIL "To: $em\n";
............................
close MAIL;
instead of that its won't work. its very important as we have seperate email address for sorting different bad emails email list.
how do i incoorporate this now with new code. please advice.
also tell me how do i send HTML email with Image along with the text just like a html page. image will change time by time so
Thank a lot for your continuous help!
|

06-20-07, 01:38 PM
|
|
Wannabe Coder
|
|
Join Date: Aug 2006
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
looks like it should work:
Code:
$msg = MIME::Lite->new(
From =>'Vikram Murarka <vikram@k****ij.com>',
To => $em,
Return-path =>'inrreturn@k****ij.com',
Reply-To =>'Vikram Murarka <vikram@k****ij.com>',
Subject => $subject,
Type =>'text',
Data => $message
);
maybe something in $em is messng up the headers. What is the value of $em?
Quote:
|
also tell me how do i send HTML email with Image along with the text just like a html page. image will change time by time so
|
This is covered in the documentation, you will need to figure that out for yourself.
Last edited by Drunken Perl Coder; 06-20-07 at 01:50 PM.
Reason: add tag line
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|