
04-08-08, 02:22 AM
|
|
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:
sub send_mail { my $lines = '/home/path to email list/list.dat'; my @lines = <EMAIL>; $mailprog = '/usr/sbin/sendmail -t'; foreach my $line (@lines) { ($em, $ser1) = split(/\:/, $line); if ($ser1 eq "A") { open (MAIL, "|$mailprog -ffxreturn\@kshitij.com") or dienice ("Can't access $mailprog!\n"); print MAIL "From: KCS <email\@kshitij.com>\n"; print MAIL "Return-Path: KCS <email\@kshitij.com>\n"; print MAIL "Reply-To: KCS <email\@kshitij.com>\n"; print MAIL "Subject: $subject1 \n"; print MAIL "$subject1 \n"; } } }
sample 2
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... my $lines = '/home/path to email list flie/list.dat'; my @lines = <EMAIL>; $mail_prog = '/usr/sbin/sendmail -t'; foreach my $line (@lines) { ($em, $ser3) = split(/\:/, $line); if ($ser3 eq "A") { 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."; print MAIL "From: KCS <email\@kshitij.com>\n"; print MAIL "Return-Path: KCS <email\@kshitij.com>\n"; print MAIL "Reply-To: Vikram Murarka <email\@kshitij.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"; print MAIL "$content \n"; open(ATTACH, "attach.txt"); @all = <ATTACH>; for ($i = 0; $i<=$#all; $i++) { $| = 1; $all[$i] =~ s/\n//g; #$all[$i] =~ s/ //g; $file = $all[$i]; #do { print "Can't find ($upload_dir/$file)"; next; } if !-r "$upload_dir/$file"; # checks the existence and readability ($ext) = $file =~ m,\. (& #91;^\.]*)$,; my $fext = $mime{$ext}; if ($fext && $fext =~ /^text/) { print MAIL "--------------$boundary\n"; print MAIL "Content-Type: $fext; charset=us-ascii; name=\"$file\"\n"; print MAIL "Content-Transfer-Encoding: 7bit\n"; print MAIL "Content-Disposition: attachment; filename=\"$file\"\n\n"; #print MAIL "$file"; open INPUT, "$upload_dir/$file"; # should be readable, we checked above [-r] print MAIL while (<INPUT>); } else { print MAIL "--------------$boundary\n"; print MAIL "Content-Type: $fext; name=\"$file\"\n"; print MAIL "Content-Transfer-Encoding: base64\n"; print MAIL "Content-Disposition: attachment; filename=\"$file\"\n\n"; my $buf; $/=0; open INPUT, "$upload_dir/$file"; # should be readable, we checked above [-r] binmode INPUT if ($^O eq 'NT' or $^O eq 'MSWin32'); while(read(INPUT, $buf, 60* 57)) { print MAIL &encode_base64 ($buf); } } } print MAIL "\n--------------$boundary--\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 }
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.
|

04-08-08, 10:04 AM
|
 |
Junior Code Guru
|
|
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by sujata_ghosh
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.
|

04-21-08, 10:45 PM
|
|
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:
Hope that helps
, Mike
__________________
Linux and Unix Tips, Tricks and Individual Advice - linuxshellaccount.blogspot.com- The Linux and Unix Menagerie
|

04-22-08, 12:21 AM
|
 |
Junior Code Guru
|
|
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by eggi
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:
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.
|

04-22-08, 07:30 AM
|
|
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?
|

04-22-08, 10:48 AM
|
 |
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.
|

04-23-08, 10:59 PM
|
|
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
|

04-24-08, 01:52 AM
|
 |
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.
|

04-24-08, 10:46 PM
|
|
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
|

06-24-08, 01:45 AM
|
|
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
|
|
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
|
|
|
|