Current location: Hot Scripts Forums » Programming Languages » Perl » Attachement help needed

Attachement help needed

Reply
  #1 (permalink)  
Old 06-18-07, 02:08 AM
sujata_ghosh sujata_ghosh is offline
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-18-07, 09:20 AM
Drunken Perl Coder Drunken Perl Coder is offline
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-19-07, 03:15 AM
sujata_ghosh sujata_ghosh is offline
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:
  1. #!/usr/bin/perl -w
  2. use MIME::Lite;
  3.     ### Create a new single-part message, to send a GIF file:
  4.     $msg = MIME::Lite->new(
  5.         From     =>'sujata@k****ij.com',
  6.         To       =>'sujata_atkcs@yahoo.com',
  7.         Cc       =>'sujata_ghosh@hotmail.com',
  8.         Subject  =>'Helloooooo, nurse!',
  9.         Type     =>'image/gif',
  10.         Encoding =>'base64',
  11.         Path     =>'/home/k****ijc/www/com/casestudy1.gif'
  12.     );
  13.     $msg->send; # send via default
  14.  

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 06-19-07, 03:35 AM
Drunken Perl Coder Drunken Perl Coder is offline
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:
  1. #!/usr/bin/perl -w
  2. use MIME::Lite;
  3.     ### Create a new single-part message, to send a GIF file:
  4.     $msg = MIME::Lite->new(
  5.         From     =>'sujata@k****ij.com',
  6.         To       =>'sujata_atkcs@yahoo.com',
  7.         Cc       =>'sujata_ghosh@hotmail.com',
  8.         Subject  =>'Helloooooo, nurse!',
  9.         Type     =>'image/gif',
  10.         Encoding =>'base64',
  11.         Path     =>'/home/k****ijc/www/com/casestudy1.gif'
  12.     );
  13.     $msg->send; # send via default
  14.  
  15. print "Content-type: text/html\n\n";
  16. print "Message sent";

Last edited by Nico; 06-19-07 at 04:18 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 06-19-07, 07:03 AM
sujata_ghosh sujata_ghosh is offline
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:
  1. sub send_mail{
  2.  
  3.  my @boundaryv = (0..9, 'A'..'F');
  4.  $PREF{'FOOTER'} =~ s/\\n/\n/g;
  5.  $| = 1;
  6.  srand(time ^ $$);
  7.  my @boundaryv = (0..9, 'A'..'F');
  8.  for (my $i = 0; $i++ < 24;)
  9.  {
  10.   $boundary .= $boundaryv&#91;rand(@boundaryv)];
  11.  }
  12.  
  13.       #foreach my $file (@files)
  14.        #{
  15.           do { push @problem, "$file"; next; } if !-r "$upload_dir/$file"; # checks the existence and readability
  16.           my ($boundary, $ext) = (undef, undef);
  17.           #--------------------------------------------------- Obtain content-type of file
  18.    ($ext) = $file =~ m,\.(&#91;^\.]*)$,;
  19.     $ext =~ tr,a-z,A-Z,;
  20.            my $fext = $mime{$ext};
  21.           #--------------------------------------------------- Generate multipart boundary
  22.      srand(time ^ $$);
  23.      for (my $i = 0; $i++ < 24;)
  24.       {
  25.              $boundary .= $boundaryv&#91;rand(@boundaryv)];
  26.       }
  27.           #--------------------------------------------------- Send attatchments etc...
  28.  
  29. 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.";
  30. print MAIL "To: $em\n";
  31. print MAIL "From: Vikram Murarka <vikram\@k****ij.com>\n";
  32. print MAIL "Return-Path: Vikram Murarka <vikram\@k****ij.com>\n";
  33. print MAIL "Reply-To: Vikram Murarka <vikram\@k****ij.com>\n";
  34. print MAIL "X-Mailer: Custom-CGI: Web Mailer v1.02\n";
  35. print MAIL "MIME-Version: 1.0\n";
  36. print MAIL "Subject: $INPUT{'subject'}\n";
  37. print MAIL "Content-Type: multipart/mixed; boundary=\"------------$boundary\"\n";
  38. print MAIL "\n";
  39. print MAIL "This is a multi-part message in MIME format.\n";
  40. print MAIL "--------------$boundary\n";
  41. print MAIL "Content-Type: text/plain; charset=us-ascii\n";
  42. print MAIL "Content-Transfer-Encoding: 7bit\n\n";
  43.            
  44. print MAIL "$subject \n";
  45. if (!$edition)
  46. {
  47. $edition = "";
  48. print MAIL "$edition";
  49. }
  50. else
  51. {
  52. print MAIL "$edition \n";
  53. }
  54. print MAIL "$time \n\n";
  55.  
  56. if ((!$inr1) && (!$inrm1))
  57. {
  58. $inr1 = "";
  59. $inrm1 = "";
  60. print MAIL "$inr1";
  61. print MAIL "$inrm1";
  62. }
  63. else
  64. {
  65. print MAIL "$inr1\n";
  66. print MAIL "$inrm1\n\n";
  67. }
  68. if ((!$fwd1) && (!$fwdm1))
  69. {
  70. $fwd1 = "";
  71. $fwd1 = "";
  72. print MAIL "$fwd1";
  73. print MAIL "$fwdm1";
  74. }
  75. else
  76. {
  77. print MAIL "$fwd1\n";
  78. print MAIL "$fwdm1\n\n\n";
  79. }
  80. if ((!$strategy1) && (!$strategym1))
  81. {
  82. $strategy1 = "";
  83. $strategym1 = "";
  84. print MAIL "$strategy1";
  85. print MAIL "$strategym1";
  86. }
  87. else
  88. {
  89. print MAIL "$strategy1\n";
  90. print MAIL "$strategym1\n\n";
  91. }
  92. if ((!$eurrs1) && (!$eurrsm1))
  93. {
  94. $eurrs1 = "";
  95. $eurrsm1 = "";
  96. print MAIL "$eurrs1";
  97. print MAIL "$eurrsm1";
  98. }
  99. else
  100. {
  101. print MAIL "$eurrsmail2\n\n";
  102. print MAIL "$eurrsmmail2\n\n\n";
  103. }
  104.  
  105. print MAIL "$dis\n\n";
  106.             print MAIL "\n";
  107.    close MAIL;
  108. }
  109.  
  110.  sub encode_base64 #($)
  111.    {
  112.       my ($res, $eol, $padding) = ("", "\n", undef);
  113.       while (($_&#91;0] =~ /(.{1,45})/gs))
  114.        {
  115.     $res .= substr(pack('u', $1), 1);
  116.     chop $res;
  117.        }
  118.       $res =~ tr#` -_#AA-Za-z0-9+/#;                 # ` help emacs
  119.       $padding = (3 - length($_&#91;0]) % 3) % 3;     # fix padding at the end
  120.       $res =~ s#.{$padding}$#'=' x $padding#e if $padding;    # pad eoedv data with ='s
  121.       $res =~ s#(.{1,76})#$1$eol#g if (length $eol);          # lines of at least 76 characters
  122.       return $res;
  123.    }


now how i will converted into it:

perl Code:
  1. #!/usr/bin/perl -w
  2. use MIME::Lite;
  3. my $message_body = "Here's the attachment file(s) you wanted<br><b>h</b>";
  4.     ### Create a new single-part message, to send a GIF file:
  5.     $msg = MIME::Lite->new(
  6.         From     =>'sujata@k****ij.com',
  7.         To       =>'sujata_atkcs@yahoo.com',
  8.         Cc       =>'sujata_ghosh@hotmail.com, [EMAIL="sujata_ghosh1@rediffmail.com'"]sujata_ghosh1@rediffmail.com'[/EMAIL],
  9.         Subject  =>'Helloooooo, nurse!',
  10.         Type     =>'application/octet-stream',
  11.         Encoding =>'base64',
  12.         Path     =>'/home/k****ijc/www/temp/inr rates.xls'
  13.     );
  14. $msg->attach (
  15.   Type => 'text/html',
  16.   Data => $message_body
  17. ) or die "Error adding the text message part: $!\n";
  18.     $msg->send; # send via default
  19. print "Content-type: text/html\n\n";
  20. 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!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 06-19-07, 02:27 PM
Drunken Perl Coder Drunken Perl Coder is offline
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 06-20-07, 12:14 AM
sujata_ghosh sujata_ghosh is offline
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 06-20-07, 03:17 AM
Drunken Perl Coder Drunken Perl Coder is offline
Wannabe Coder
 
Join Date: Aug 2006
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
perl Code:
  1. my $message = "$subject \n";
  2. if (!$edition)
  3. {
  4. $edition = "";
  5. $message .= $edition;
  6. }
  7. else
  8. {
  9. $message .= "$edition \n";
  10. }
  11. $message .= "$time \n\n";
  12.  
  13. if ((!$inr1) && (!$inrm1))
  14. {
  15. $inr1 = "";
  16. $inrm1 = "";
  17. $message .= $inr1;
  18. $message .= $inrm1;
  19. }
  20. else
  21. {
  22. $message .= "$inr1\n";
  23. $message .= "$inrm1\n\n";
  24. }
  25. if ((!$fwd1) && (!$fwdm1))
  26. {
  27. $fwd1 = "";
  28. $fwd1 = "";
  29. $message .= $fwd1;
  30. $message .= $fwdm1;
  31. }
  32. else
  33. {
  34. $message .= "$fwd1\n";
  35. $message .= "$fwdm1\n\n\n";
  36. }
  37. if ((!$strategy1) && (!$strategym1))
  38. {
  39. $strategy1 = "";
  40. $strategym1 = "";
  41. $message .= $strategy1;
  42. $message .= $strategym1;
  43. }
  44. else
  45. {
  46. $message .= "$strategy1\n";
  47. $message .= "$strategym1\n\n";
  48. }
  49. if ((!$eurrs1) && (!$eurrsm1))
  50. {
  51. $eurrs1 = "";
  52. $eurrsm1 = "";
  53. $message .= $eurrs1;
  54. $message .= $eurrsm1;
  55. }
  56. else
  57. {
  58. $message .= "$eurrsmail2\n\n";
  59. $message .= "$eurrsmmail2\n\n\n";
  60. }
  61.  
  62. $message .= "$dis\n\n";
  63. $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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 06-20-07, 07:13 AM
sujata_ghosh sujata_ghosh is offline
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 06-20-07, 01:38 PM
Drunken Perl Coder Drunken Perl Coder is offline
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programmer Needed for File hosting script! Fabolous Job Offers & Assistance 3 06-15-06 10:56 PM
Senior Programmer needed in Newport Beach, CA! DAMC123 Job Offers & Assistance 0 05-01-06 06:13 PM
Partner Needed for New Shoutcast Hosting Company HopesDespair Job Offers & Assistance 0 06-17-05 08:39 PM
Scripts Needed? ezcore General HotScripts Site Discussion 4 08-27-04 03:27 PM
will pay. php script needed. upload, resize, & email jamjammo Script Requests 4 02-29-04 08:30 PM


All times are GMT -5. The time now is 07:15 PM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.