+ Reply to Thread
Results 1 to 2 of 2

Thread: Mailer script Example

  1. #1

    Mailer script Example

    I'd like a script for mailing , Thanks in advance.
    Last edited by r.vector; 11-12-2012 at 03:51 AM.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Here is a quick tutorial on how to create a simple mailer script , so here is the snippet :
    use strict; use warnings; require 5.008;
    my $to       = "them\@gmail.com";
    my $subject  = "Test";
    my $reply_to = "you\@gmail.com";
    my $content  = "This is a test";
    #check address (from perlfaq 9)
    my $atom       = qr{[a-zA-Z0-9_!#\$\%&'*+/=?\^`{}~|\-]+};
    my $dot_atom   = qr{$atom(?:\.$atom)*};
    my $quoted     = qr{"(?:\\[^]|[^\\"])*"};
    my $local      = qr{(?:$dot_atom|$quoted)};
    my $quotedpair = qr{\\[\x00-\x09\x0B-\x0c\x0e-\x7e]};
    my $domain_lit = qr{\[(?:$quotedpair|[\x21-\x5a\x5e-\x7e])*\]};
    my $domain     = qr{(?:$dot_atom|$domain_lit)};
    my $addr_spec  = qr{$local\@$domain};
    die ( "Invalid To: address $to\n" ) unless ($to =~ /^${addr_spec}$/);
    die ( "Invalid reply_to: address $reply_to\n" ) unless ($reply_to =~ /^${addr_spec}$/);
    my $sendmail = "/usr/sbin/sendmail -t -oi";
    my $send_to       = "To: $to";
    my $send_reply_to = "Reply-to: $reply_to";
    my $send_subject  = "Subject: $subject";
    local $\ = "\n";
    open( SENDMAIL, "|$sendmail" ) or die "Cannot open $sendmail: $!";
    print SENDMAIL $send_to;
    print SENDMAIL $send_reply_to;
    print SENDMAIL $send_subject;
    #extra \n is REQUIRED
    print SENDMAIL "Content-type: text/plain\n";
    print SENDMAIL $content;
    close( SENDMAIL );

+ Reply to Thread

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts