Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I send an email using sendmail?

Sending email

How do I send an email using sendmail?

by  tanderso  Posted    (Edited  )
# 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
[tt]
open (MAIL, "| /usr/sbin/sendmail -t >& /dev/null");
[/tt]
# 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>
[tt]
print MAIL qq~To: "$title" <$email_addr>\n~;
[/tt]
# If you want to send to a list, send the mail only once,
# but make each address a blind carbon copy.
[tt]
print MAIL qq~Bcc: ~;
my $address = pop(@LIST);
print MAIL qq~$address~;
foreach $address (@LIST) {print MAIL qq~, $address~;}
[/tt]
# Include the remaining header info
[tt]
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~;
[/tt]
# 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.
[tt]
print MAIL qq~Content-Type: text/plain\n\n~;
[/tt]
# Then, print the body of your email to the mail stream
[tt]
print MAIL qq~$body_text\n~;
[/tt]
# 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.
[tt]
print MAIL qq~.~;
[/tt]
# 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.
[tt]
close(MAIL);
[/tt]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top