Current location: Hot Scripts Forums » Programming Languages » Perl » Send mail authentication


Send mail authentication

Reply
  #1 (permalink)  
Old 04-08-08, 02:22 AM
sujata_ghosh sujata_ghosh is offline
Wannabe Coder
 
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
Send mail authentication

hi to all!

i am using this followng CGI script to send email from a Form to the email list, this list has 200 email address. the form is working fine, but the problem is our emails are going to the client junk email folder, not on inbox. so our hosting company told us to use SMTP authenctication code along with current code:

sample 1

perl Code:
  1. sub send_mail
  2. {
  3. my $lines = '/home/path to email list/list.dat';
  4. open(EMAIL, $lines);
  5. my @lines = <EMAIL>;
  6. close(EMAIL);
  7. $mailprog = '/usr/sbin/sendmail -t';
  8. foreach my $line (@lines)
  9. {
  10. ($em, $ser1) = split(/\:/, $line);
  11.  
  12. if ($ser1 eq "A")
  13. {
  14. open (MAIL, "|$mailprog -ffxreturn\@kshitij.com") or dienice("Can't access $mailprog!\n");
  15. print MAIL "From: KCS <email\@kshitij.com>\n";
  16. print MAIL "Return-Path: KCS <email\@kshitij.com>\n";
  17. print MAIL "Reply-To: KCS <email\@kshitij.com>\n";
  18. print MAIL "Subject: $subject1 \n";
  19. print MAIL "To: $em \n";
  20. print MAIL "$subject1 \n";
  21. print MAIL "$content\n";
  22.  
  23. close(MAIL);
  24. }
  25. }
  26. }

sample 2

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.     my $lines = '/home/path to email list flie/list.dat';
  30.     open(EMAIL, $lines);
  31.     my @lines = <EMAIL>;
  32.     close(EMAIL);
  33.     $mail_prog = '/usr/sbin/sendmail -t';
  34.  
  35.     foreach my $line (@lines)
  36. {
  37.  
  38. ($em, $ser3) = split(/\:/, $line);
  39.  
  40.  
  41. if ($ser3 eq "A")
  42. {
  43. open MAIL, "| $mail_prog -finrreturn\@kshitij.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.";
  44. print MAIL "To: $em\n";
  45. print MAIL "From: KCS <email\@kshitij.com>\n";
  46. print MAIL "Return-Path: KCS <email\@kshitij.com>\n";
  47. print MAIL "Reply-To: Vikram Murarka <email\@kshitij.com>\n";
  48. print MAIL "X-Mailer: Custom-CGI: Web Mailer v1.02\n";
  49. print MAIL "MIME-Version: 1.0\n";
  50. print MAIL "Subject: $INPUT{'subject'}\n";
  51. print MAIL "Content-Type: multipart/mixed; boundary=\"------------$boundary\"\n";
  52. print MAIL "\n";
  53. print MAIL "This is a multi-part message in MIME format.\n";
  54. print MAIL "--------------$boundary\n";
  55. print MAIL "Content-Type: text/plain; charset=us-ascii\n";
  56. print MAIL "Content-Transfer-Encoding: 7bit\n\n";
  57.            
  58. print MAIL "$subject \n";
  59. print MAIL "$content \n";
  60. close MAIL;
  61.  
  62.  open(ATTACH, "attach.txt");
  63.  @all = <ATTACH>;
  64.  close(ATTACH);
  65.  
  66.  
  67.    
  68.  for ($i = 0; $i<=$#all; $i++) {
  69.   $| = 1;
  70.   $all&#91;$i] =~ s/\n//g;
  71.   #$all[$i] =~ s/ //g;
  72.   $file = $all&#91;$i];
  73.   #do { print "Can't find ($upload_dir/$file)"; next; } if !-r "$upload_dir/$file"; # checks the existence and readability
  74.  
  75.   ($ext) = $file =~ m,\.(&#91;^\.]*)$,;
  76.    $ext =~ tr,a-z,A-Z,;
  77.         my $fext = $mime{$ext};
  78.   if ($fext && $fext =~ /^text/) {
  79.    print MAIL "--------------$boundary\n";
  80.    print MAIL "Content-Type: $fext; charset=us-ascii; name=\"$file\"\n";
  81.    print MAIL "Content-Transfer-Encoding: 7bit\n";
  82.    print MAIL "Content-Disposition: attachment; filename=\"$file\"\n\n";
  83.    #print MAIL "$file";
  84.  
  85.    open INPUT, "$upload_dir/$file"; # should be readable, we checked above [-r]
  86.    print MAIL while (<INPUT>);
  87.    close INPUT;
  88.   } else {
  89.  
  90.    print MAIL "--------------$boundary\n";
  91.    print MAIL "Content-Type: $fext; name=\"$file\"\n";
  92.    print MAIL "Content-Transfer-Encoding: base64\n";
  93.    print MAIL "Content-Disposition: attachment; filename=\"$file\"\n\n";
  94.    
  95.    my $buf; $/=0;
  96.    open INPUT, "$upload_dir/$file"; # should be readable, we checked above [-r]
  97.    binmode INPUT if ($^O eq 'NT' or $^O eq 'MSWin32');
  98.    while(read(INPUT, $buf, 60*57))
  99.    {
  100.    print MAIL &encode_base64($buf);
  101.    }
  102.    close INPUT;
  103.          }   
  104.   }
  105.    print MAIL "\n--------------$boundary--\n";
  106.              print MAIL "\n";
  107.    close MAIL;
  108.  
  109. }
  110.  
  111. }
  112.  
  113. }
  114.  
  115.  
  116.  
  117.  sub encode_base64 #($)
  118.    {
  119.       my ($res, $eol, $padding) = ("", "\n", undef);
  120.       while (($_&#91;0] =~ /(.{1,45})/gs))
  121.        {
  122.     $res .= substr(pack('u', $1), 1);
  123.     chop $res;
  124.        }
  125.       $res =~ tr#` -_#AA-Za-z0-9+/#;                 # ` help emacs
  126.       $padding = (3 - length($_&#91;0]) % 3) % 3;     # fix padding at the end
  127.       $res =~ s#.{$padding}$#'=' x $padding#e if $padding;    # pad eoedv data with ='s
  128.       $res =~ s#(.{1,76})#$1$eol#g if (length $eol);          # lines of at least 76 characters
  129.       return $res;
  130.    }

i addes 2 types of send mail coding i am using currently. 1st one is with out attachement and 2nd one is with attachment.

can any one help me on this. if you need any more info please let me know.

Thanks.

Last edited by Nico; 04-08-08 at 05:25 AM. Reason: [highlight=perl] wrappers.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-08-08, 10:04 AM
curbview.com's Avatar
curbview.com curbview.com is offline
Junior Code Guru
 
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by sujata_ghosh View Post
so our hosting company told us to use SMTP authenctication code along with current code:
If your hosting company really said to add SMTP authentication, then I hope they were referring to having your SPF (google the term) set. If the mail is being delivered but winds up in the junk mail folder, then there is no need to authenticate with your server. A lot of ISP's now look to see if the originating server/sender has an "SPF Record"...If not, mail will be flagged.
__________________
Whatever you decide, you should make sure best security methods are used and practiced. Should you really need more help, PM me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 04-21-08, 10:45 PM
eggi eggi is offline
Newbie Coder
 
Join Date: Oct 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Hey There,

You can also add a field, in the section where you write your headers, to set the precedence, so it doesn't send out as junk email, like:

Code:
print MAIL "X-Priority: 2\n";
Hope that helps

, Mike
__________________
Linux and Unix Tips, Tricks and Individual Advice - linuxshellaccount.blogspot.com- The Linux and Unix Menagerie
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 04-22-08, 12:21 AM
curbview.com's Avatar
curbview.com curbview.com is offline
Junior Code Guru
 
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by eggi View Post
Hey There,

You can also add a field, in the section where you write your headers, to set the precedence, so it doesn't send out as junk email, like:

Code:
print MAIL "X-Priority: 2\n";
Hope that helps

, Mike
That old "trick" doesn't work. Legit hosting providers as well as gmail and yahoo block mail if the SPF is not set. ~Google is your friend~
__________________
Whatever you decide, you should make sure best security methods are used and practiced. Should you really need more help, PM me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 04-22-08, 07:30 AM
sujata_ghosh sujata_ghosh is offline
Wannabe Coder
 
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks guys!

then how i will set SFP?

any idea?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 04-22-08, 10:48 AM
curbview.com's Avatar
curbview.com curbview.com is offline
Junior Code Guru
 
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
Simply contact your hosting provider. It is SPF not SFP though.
__________________
Whatever you decide, you should make sure best security methods are used and practiced. Should you really need more help, PM me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 04-23-08, 10:59 PM
eggi eggi is offline
Newbie Coder
 
Join Date: Oct 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
There are few modules on cpan.org that can make it a bit easier to incorporate in your script. Check here:

http://search.cpan.org/search?query=SPF&mode=all

Too bad that old "trick" doesn't work anymore; it was good while it lasted.

Best wishes,

Mike
__________________
Linux and Unix Tips, Tricks and Individual Advice - linuxshellaccount.blogspot.com- The Linux and Unix Menagerie
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 04-24-08, 01:52 AM
curbview.com's Avatar
curbview.com curbview.com is offline
Junior Code Guru
 
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Mike, sorry to inform you, but your suggestion is incorrect... I mean, what good is it for Sujata to use a Perl module that only checks the SPF record?

That is NOT the problem Sujata has NOR relevant to what Sujata needs to overcome the "JUNK MAIL" problem.

Please re-read the OP's original request before possibly confusing anyone reading this thread.
__________________
Whatever you decide, you should make sure best security methods are used and practiced. Should you really need more help, PM me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 04-24-08, 10:46 PM
eggi eggi is offline
Newbie Coder
 
Join Date: Oct 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
No problem,

I don't mean to confuse, but my understanding, from the implementations I've seen, is that SPF records (or lack thereof) are used to classify mail from a host, ip or domain as junk and "not accept" mail from the sender. (Perhaps the use of the term "junk mail" is too dated and interpreted differently by old dogs like myself

With that in my mind, my thought was that the issue may be related to an additional factor, since he stated that his mail was actually making it into his recipients junk email box.

Hopefully that clarifies my intention when I made my initial post.

Take care and I hope that you're problem gets resolved soon.

Best wishes,

Mike
__________________
Linux and Unix Tips, Tricks and Individual Advice - linuxshellaccount.blogspot.com- The Linux and Unix Menagerie
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 06-24-08, 01:45 AM
sujata_ghosh sujata_ghosh is offline
Wannabe Coder
 
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
sorry guys!

i was busy in some other problem of same site. so couldn't follow you up. i am realy sorry.

so please suggest me what do i need to do to overcome this problem for forever? its not clear to me that what do i need to do. please suggest.

Thanks once more for your help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare 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
Attachement help needed sujata_ghosh Perl 18 06-22-07 02:00 PM
Send Mail sharad PHP 3 09-11-06 09:55 AM
send mail to all msn contacts de_majoor Script Requests 2 09-20-05 02:56 PM


All times are GMT -5. The time now is 06:43 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.