Sponsored Content
Full Discussion: SendMail in Perl
Top Forums Shell Programming and Scripting SendMail in Perl Post 81461 by cbkihong on Friday 19th of August 2005 08:59:16 PM
Old 08-19-2005
Now you need to be aware that sending mail in your snippet involves purely invoking an external sendmail executable to send the mail for you. So the only direct way you can check the status is by its return value.

I'm not sure about what sendmail return values will provide (let alone availability of other sendmail clones such as qmail or postfix which may vary in behaviour WRT this). But I think sendmail's return value is not any much useful. Don't forget sendmail does not send the mail immediately but queued it for delivery so the sendmail process will immediately return without waiting for delivery. That is, mail sending with sendmail is an asynchronous operation so there is not much status indication you can get, beyond obvious misconfigurations such as the sendmail executable is not found which may get trapped! So probably, the sendmail return value is always 0 (successful) so you don't have much to tell from it (and so it will nearly always be successful so eval() won't work).

With a programming mind, I generally recommend this method:

(1) Generate mail with an additional header with an ID that your program can use to identify the message. e.g.

X-MsgID: 20050820000001

Note that custom headers should start with 'X-'. We need a custom message ID because we cannot get the actual message ID as we send it, so we need to embed our own.

Save information about this mail with this message ID in some persistent storage (such as database or files) that allows you to, say, associate this message with a particular application activity that triggers this message.

(2a) At sendmail, capture the return mail by redirecting incoming mail to a program (setting /etc/mail/aliases or similar) instead of to mailbox. The program will be invoked with the return mail content. In the program, you can extract the message ID from the custom ID we inserted. Then we know the mail cannot be sent (or deferred for later retry).

(2b) Some others who have no say over mail server configuration may read the destination mailbox (through POP3 for instance) instead.

(3) Some people may even want to extract the actual message ID for extracting the relevant record from /var/log/maillog. But I usually tend to think this is too much of a trouble.

This is a lot of programming. So are there existing modules you can use to help out a little bit? Probably yes. You may want to think about this:

http://search.cpan.org/~freeside/Mai...ounceParser.pm

I haven't used it before so I'm not sure if it's good. From the POD it seems to do the most important part of the trick though.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sendmail

What is teh command to run sendmail in the normal operation mode for Red Hat 7.1? Thanks. (1 Reply)
Discussion started by: kara
1 Replies

2. UNIX for Dummies Questions & Answers

sendmail.cf

Dear All , I have Linux Red Hat 6.1 , and i have sendmail (8.11.6 ) . i have big problem with spammers , i was looking in sendmail.cf configuration file and i saw this option , i tried it but it failed : the option is : # file containing known spammers by email,domain,ip Kjunk hash... (1 Reply)
Discussion started by: tamemi
1 Replies

3. UNIX for Dummies Questions & Answers

Sendmail

I have a Sendmail (Red Hat 9.0, Sendmail 8.12.8-4)server set up on the local network. I am able to send mail just fine, and when I copy error messages from the root mail account to my test user, I can download those to Outlook just fine. My problem is that I cannot send messages to my testaccount... (2 Replies)
Discussion started by: Jody
2 Replies

4. UNIX for Advanced & Expert Users

sendmail

When I try to use mailx on AIX 5.2 I get the following message: "The flags you gave make no sense since you're not sending mail." The type of command sent is as follows: mailx -s "Test" -c gilstanden@hotmail.com < sendmail.pid but it just gives the message referenced previously. Do I need to... (1 Reply)
Discussion started by: gstanden
1 Replies

5. Solaris

sendmail.cf

when mailing from server sender address showing in this format: username@hostname.oops.co.uk What changes are required to remove the hostname from the senders address. Solaris 9 thanks :) (5 Replies)
Discussion started by: smcart
5 Replies

6. Shell Programming and Scripting

Perl: Sendmail - Permission denied

Hi, I'm trying to write a simple mail handler perl script for a website I'm working on. I've managed to installed sendmail yesterday, and I'm currently trying to get the script to work. I'm getting an error however. Here's the block of perl code I'm using: open(MAIL, "| $sendmailpath -t")... (7 Replies)
Discussion started by: LNC
7 Replies

7. UNIX for Dummies Questions & Answers

run a perl.script upon receiving an email in Sendmail

Hi All I am newbie with Sendmail and Linux in general. We use sendmail for outgoing and incoming mails. Once our server receives a certain email xxx@yyy.com we would like to run a PERL script doing some task wiht it. Can you address me a little bit on that topic? In order to do that the... (0 Replies)
Discussion started by: manustone
0 Replies

8. UNIX for Advanced & Expert Users

Sendmail questions, SCO 5.0.6 sendmail 8.11.0

I am running SCO 5.0.6 and using sendmail 8.11.0 and having issues with smtp authentication. When trying to send mail the following message will kick back. (reason: 530 5.7.1 Authentication required) 530 5.7.1 Authentication required Not sure what needs to be tweeked in sendmail.cf but I... (1 Reply)
Discussion started by: ziggy6
1 Replies

9. Solaris

Clarifying sendmail configuration - sendmail-client offline

Hi all, I have read about sendmail running as 2 separate process. 1 as a MSP, and the other as the real daemon or MTA. In my current configuration, the sendmail-client is disabled. Both submit.cf and sendmail.cf are left as default untouch I do not specified any mailhost... (3 Replies)
Discussion started by: javanoob
3 Replies

10. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies
mail_intro(7)						 Miscellaneous Information Manual					     mail_intro(7)

NAME
mail_intro - Introductory information on the Tru64 UNIX mail system DESCRIPTION
The Tru64 UNIX mail system enables you to exchange mail with other users on your system, as well as with other systems connected to your local network and with users on other networks (provided your system and network are connected to other networks). Mail System Concepts Mail systems consist of the following components: User agent - The user agent provides the interface through which you interact with the mail system. Generally, the user interface enables you to create, send, receive, read, save, and manage your mail messages. Tru64 UNIX provides the following user agents: CDE's Mailer - For further information, see the Common Desktop Environment: User's Guide . Mail or mailx - For further information, see the Command and Shell User's Guide . The Rand Message Handling program (MH) - For further information, see the mh(1) and xmh(1X) reference pages. Transport agent - The transport agent provides an interface between the user agents and the delivery agents. The sendmail command is a transfer agent. Delivery agent - The delivery agent provides the mechanism for delivering the mail messages to end users, systems, and networks. The binmail and deliver commands are delivery agents for standard mail and IMAP mail, respectively. In Tru64 UNIX, the sendmail program acts as both the transport and delivery agent. It does so by implementing the Simple Mail Transfer Pro- tocol (SMTP), which is the specification for the Internet's delivery agent. Initially standards did not exist for mail addresses and computer networks. Many different address formats and network protocols exist. Mail programs must interact with different network protocols, as well as recognize and reformat different mail address formats. Fortu- nately, these difficulties were recognized and standards, such as the Standard for the Format of ARPA Internet Text Messages (RFC 822) and The Domain Naming Convention for Internet User Applications (RFC 819), emerged. A mail program still must recognize addresses in various formats and communicate with different network protocols. The sendmail program addresses these issues through the use of the sendmail.cf configuration file. The Sendmail Configuration File The sendmail.cf configuration file provides the sendmail program with the information to perform the following tasks: Choose delivery agents Use address rewriting rules Define mail header information Perform some routing When it starts, the sendmail program reads the sendmail.cf configuration file. The information in the sendmail.cf configuration file enables sendmail to rewrite the addresses of mail it receives into the address form expected by the mail delivery agent. It also enables sendmail to set parameters and arguments to the mail delivery program. The configuration file contains information that is used for the following functions: Define message precedence for mail delivery Define administrative IDs to override the sender's address Define message headings Define the mail program to use Set options used by the sendmail command The default Tru64 UNIX configuration file (located in /var/adm/sendmail/sendmail.cf) is adequate for most standalone systems. However, if you plan to connect your system to a network, you will have to modify the sendmail.cf file. Tru64 UNIX provides the mailconfig and mailsetup utilities, which you can use to create mail configuration files. If you prefer to manipu- late the configuration file manually, you should use the m4 macros provided for this purpose. (See the sendmail.m4 reference page.) For more information on configuring mail, see the Network Administration manual. RELATED INFORMATION
Commands: binmail(1), mailconfig(8), mailsetup(8), mailx(1), sendmail(8), sendmail.m4(8) Files: sendmail.cf(4) Network Administration Standard for the Format of ARPA Internet Text Messages (RFC 822) The Domain Naming Convention for Internet User Applications (RFC 819) UNIX System Administration Handbook, Englewood Cliffs, N.J.: Prentice Hall, Inc., 1989. delim off mail_intro(7)
All times are GMT -4. The time now is 02:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy