Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

SMTP authentication

by voner (Initiate)
on Oct 11, 2013 at 11:37 UTC ( #1057869=perlquestion: print w/replies, xml ) Need Help??
voner has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks :) I have a question. I am not so familiar with perl, thus I need a little help. I have a small business and I've found a script to send buletin to my customers (~180 costumers), the script working awesome, but it doesn't has SMTP authentication. The headers of received mail looks terible, also some of my clents are unable to receive them. I am using recent centos + cpanel, I have created email account and SMTP settings, thus could you please help me to modify this script for better working. Here is the script:
#!/usr/bin/perl -w #user configuration begin# $mailprg = "/usr/sbin/sendmail"; #path to your mail program $delay = 0.25; #delay in seconds $from = 'Coname<>'; #from address in your m +ail $subject = 'Trial send'; #subject of newsletter. u can add + the spl code $USERNAME$ $maildata = "mail.dat"; #mail address file $msgtemplate = "message.template"; #message template file #user configuration end# if(@ARGV){ $i = 0; while($ARGV[$i]){ if($ARGV[$i] eq "--help"){ print "Command Line Options:\n\n"; print "-t\tTest how the message will be formatted\n"; print "-d\tData file listing the email addresses\n"; print "-m\tMessage template file\n"; print "-s\tSubject\n"; print "-f\tFrom address. Quote for security reasons\n"; die "\nMore information at\n"; } elsif($ARGV[$i]=~/^-/){ $arr = substr($ARGV[$i],1,1); if($arr eq "d"){ $maildata = $ARGV[$i+1]; $i+=2; } elsif($arr eq "m"){ $msgtemplate = $ARGV[$i+1]; $i+=2; } elsif($arr eq "t"){ $testflag = 1; $i++; } elsif($arr eq "s"){ $subject = $ARGV[$i+1]; $i+=2; } elsif($arr eq "f"){ $from = $ARGV[$i+1]; $i+=2; } else{ die "Wrong argument!"; } } } } open TEMPLATE, $msgtemplate || die "Cannot open template file!\n"; while(<TEMPLATE>){ $msg .= $_; } close TEMPLATE || die "Cannot close template file!\n"; open MAILFILE,"$maildata" || die "Cannot open data file!\n"; while(<MAILFILE>){ chomp($_); @arr = split(/\@/,$_); $arr[0] = ucfirst($arr[0]); $tmp = $msg; $tmp =~ s/\$USERNAME\$/$arr[0]/g; $subject =~ s/\$USERNAME\$/$arr[0]/g; $temp = "To: $arr[0]<$_>\n"; $temp .= "From: $from\n"; $temp .= "Subject: $subject\n\n\n"; $temp .= $tmp; if($testflag){ print $temp; last; } else{ open MAILPRG,"|$mailprg -t" || die "Cannot open mail program!\ +n"; print MAILPRG $temp; close MAILPRG || die "Cannot close mailprogram!\n"; if($delay < 0){ $delay = 1; sleep $delay; } elsif($delay < 1){ select(undef,undef,undef,$delay); } else{ sleep $delay; } print $_,"\n"; } } close MAILFILE || die "Cannot close data file!\n";
All I need to not use sendmail and just a written mail, I need to authenticate to SMTP with mail SMTP settings and send those mails properly. Thank you and sorry for my english.

Replies are listed 'Best First'.
Re: SMTP authentication
by jethro (Monsignor) on Oct 11, 2013 at 12:17 UTC

    There are a few client modules on CPAN, searching shows smtp and smtps.

Re: SMTP authentication
by ww (Archbishop) on Oct 11, 2013 at 12:52 UTC
    You're asking for free work... to support your business? Sure looks like it.
    Answer: nope. PM is about helping you learn Perl and thus, how to do your own work.

    The Monastery's role is NOT to play 'Free-code-amatic.

    But I'll be happy to help -- as a $contractor or $employee.

    Or perhaps you should post your request to one of the many sites (for example,, inter alia) where those with $$$work to do post $$$jobs for consideration by those seeking to earn $$$.

Re: SMTP authentication
by Anonymous Monk on Oct 11, 2013 at 11:41 UTC

    I am not so familiar with perl, thus I need a little help. ...thus could you please help me to modify this script for better working.

    Sorry no, this website is not a code writing service. Try TFMail, if it works for your purposes , great, if it doesn't, ...


      I don't need you to write my code :), just let me know how to modify it to use SMTP.

      Anyway, thank you for your reply.


        I don't need you to write my code :), just let me know how to modify it to use SMTP

        Ok, read the various sendmail manual to figure out how to drive "sendmail" to perform "SMTP auth" , and then perform appropriate SMOP modifications

        Is this better?

Re: SMTP authentication
by bitingduck (Chaplain) on Oct 12, 2013 at 07:34 UTC

    To add another mailer option or two: Email::MIME and Email::Sender both look pretty easy to use to construct and send mail via SMTP. I've used MIME::Lite recently and you can get something working in a few minutes just from cutting and pasting the examples, but the maintainer says it's getting weird bug reports and recommends not using it, since there are less buggy alternatives (which I linked to above) that are more actively maintained.

Re: SMTP authentication
by voner (Initiate) on Oct 12, 2013 at 16:14 UTC


    Thank you for all answers, It seems my question was incorrectly asked and I am sorry about that. I am not programer but I'm learing in my free time. I will read all about the modules which you provide me with. Thank you once again.

    Regards :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1057869]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2017-10-17 19:03 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (235 votes). Check out past polls.