×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Sending email

How do I send an email using sendmail? by tanderso
Posted: 26 Dec 00

# Open a stream, piped to your sendmail program.  You
# should send the process to the background and send all
# output to /dev/null so that your program does not hang
# if the mail queue takes awhile

open (MAIL, "| /usr/sbin/sendmail -t >& /dev/null");

# Print the To: field to your mail stream.  You can either
# enter the recipient email by itself, or in the standard
# format of Name <address>

print MAIL qq~To: "$title" <$email_addr>\n~;

# If you want to send to a list, send the mail only once,
# but make each address a blind carbon copy.

print MAIL qq~Bcc: ~;
my $address = pop(@LIST);
print MAIL qq~$address~;
foreach $address (@LIST) {print MAIL qq~, $address~;}

# Include the remaining header info

print MAIL qq~\nFrom: "$return_name" <$return_addr>\n~;
print MAIL qq~Reply-To: $return_addr\n~;
print MAIL qq~List-Unsubscribe: $return_addr\n~;
print MAIL qq~Subject: $subject\n~;

# To send HTML formatted emails, your Content-Type needs
# to be text/html.  Otherwise it is text/plain.  This being
# the last line before the body, there are two newlines at
# the end of this line.

print MAIL qq~Content-Type: text/plain\n\n~;

# Then, print the body of your email to the mail stream

print MAIL qq~$body_text\n~;

# And close with a period on a line of its own.  This is
# not necessary, since the mail will send when you close
# the stream, but it is the correct sendmail format.

print MAIL qq~.~;

# Close your mail stream, and your email will be sent to
# the sendmail queue to be sent out.  Sendmail will figure
# out the best way of doing this for you.  If you have a
# large list, it may send a few emails every few minutes.

close(MAIL);

Back to Perl FAQ Index
Back to Perl Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close