Sponsored Content
Full Discussion: sendmail in script.
Top Forums UNIX for Dummies Questions & Answers sendmail in script. Post 42877 by davidg on Thursday 6th of November 2003 07:21:21 AM
Old 11-06-2003
Hi Suresh,

I had the same problem. Now after some reconfig I re-wrote an excisting script. This is what I re-use for each program that needs to mail something.
Hope you understand it a little, it's a cool one.

Regs David
Code:
#!/bin/ksh

# We have to invoke a mailer that has no escape possibilities...
#
# The only one I know of would be sendmail, but this is very ugly
# to invoke directly because we have no control of To: and
# Subject: lines...
#
# This wrapper writes some of the Header-Fields before forwarding the
# mail itself in the body
#
# usage: start-mail mailaddr subject

# you might want to change the following line to set a sepcific from: address
#sender=`/usr/bin/id|/usr/bin/sed 's/.*(\(.*\)) .*/\1/'`
sender='root@'`/usr/bin/hostname`

# it's a bad idea to use temporary files with predictable names that are
# located in a world-writable /tmp dir because other local users may create
# sym-links pointing to another file...
#
# better use a tmp-dir that is only accessible by the logsurfer user
# change the following line!
# example: TMP=/home/logsurfer
TMP=/tmp

recepient="$1"
subject="$2"
message="$3"

if [ $# -eq 0 ]; then
	echo 'usage: start-mail mailaddr subject' 1>&2
	exit 1
fi

/bin/rm -f $TMP/start-mail.$$

echo "From: $sender" > $TMP/start-mail.$$
echo "To: $recepient" | /usr/bin/tr -cd '[\040-\176]' >> $TMP/start-mail.$$
echo "" >> $TMP/start-mail.$$
if [ $# -gt 1 ]; then
	shift
	echo "Subject: $subject" | /usr/bin/tr -cd '[\040-\176]' >> $TMP/start-mail.$$
	echo "" >> $TMP/start-mail.$$
else
	echo "Subject: (no subject given - logsurfer output)" >> $TMP/start-mail.$$
fi
echo "" >> $TMP/start-mail.$$
echo "$message" | /usr/bin/tr -cd '[\040-\176]' >>/$TMP/start-mail.$$
echo "\n." >>/$TMP/start-mail.$$


cat $TMP/start-mail.$$ - | /usr/lib/sendmail -odq -t

/bin/rm -f $TMP/start-mail.$$

added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 12:20 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Issues with cronjob : Script using sendmail

Hi All, I am new to unix. I have created a cron job, that sends mail using sendmail utility. Am facing a unique problem while making a cron job for this script. In the script I append a file to my mail using 'cat' command. cat $report >> $mailMsg & this $mailMsg is used as mail... (7 Replies)
Discussion started by: anshulporwal
7 Replies

2. Shell Programming and Scripting

Using sendmail utility in K Shell script

Hi, I am new to shell scripting and thus any help will be highly appreciated. I need to write a K shell script where in the email sending feature should be handled by sendmail utility and I have come up with the following : #!/usr/bin/ksh echo "This is a test mailest mail" | /usr/lib/sendmail... (4 Replies)
Discussion started by: sdiptanil
4 Replies

3. Shell Programming and Scripting

need help with my sendmail script

hi all, i'm trying to use sendmail to send a message in html format with attachments but having some issues with the attachments. below is my code. ATTACH1="/export/home/adshocker/attach.prog" ATTACH_NAME1=${ATTACH1##*/} echo "ATTACH_NAME1=$ATTACH_NAME1"... (2 Replies)
Discussion started by: adshocker
2 Replies

4. Shell Programming and Scripting

Sendmail works from script, but not when called from Apache

Hi, I am building a web interface to run a series of shell scripts that reside on the web server. The bash script are written such that they can be used independently for the task they are meant for, or the same scripts can be run from this web UI. The scripts are mostly for doing software... (1 Reply)
Discussion started by: MacQAGuy
1 Replies

5. UNIX for Advanced & Expert Users

Sendmail Script don't deliver mails

Hi, i've got a problem with a sendmail script, which sends HTML mails. Some mail will rejected by the mail server, because the fqdn doesn't exist. Where can i set the sender-domainname by sendmail? My mail server say: "Sender address rejected: Domain not found;", which is correct... (3 Replies)
Discussion started by: rainbowwarrior
3 Replies

6. Shell Programming and Scripting

Help with integrating shell script with sendmail

Hi friends, I want to converting a task ,of making few words in my task mail bold and underlined sometimes, automated through sendmail. I have never used sendmail/mailx before. What i want is my ouput which looks like below: +++++++++++++++ DETAILS: sqlid:6mbiosdfsdff parsing_schema_name:... (1 Reply)
Discussion started by: kunwar
1 Replies

7. Shell Programming and Scripting

Sendmail script not working

I am facing a peculiar problem in AIX 6.1 I can execute sendmail command using the following script sendmail -f sender -v recepient Body of email ^dThe command executes successfully and mail is sent to the intended recepient but when I try to use the attached script, the mail is not sent... (3 Replies)
Discussion started by: abhilashnair
3 Replies

8. 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

9. Shell Programming and Scripting

Python script for sendmail limitation

Hello, I have a web server (apache, php-fpm) with several vhosts sending mail through php. In order to avoid IP blacklisting when spam is sent by a domain i'm looking for a way to setup a rate limit for outgoing mail and when this limit is reached I want to receive an email warning me that a... (1 Reply)
Discussion started by: draugr
1 Replies

10. Shell Programming and Scripting

Script to connect to remote and sendmail.

Hello, Kindly guide. SendMail function on my script is not working, but it works manually. Any better way to handle the script is appreciable. #!/bin/sh GetHostConnection() { truncate --size 0 /home/web/for_mail.out while read -r lines ; do ip=`echo $lines | awk '{print... (9 Replies)
Discussion started by: sadique.manzar
9 Replies
mail.local(1M)						  System Administration Commands					    mail.local(1M)

NAME
mail.local - store mail in a mailbox SYNOPSIS
/usr/lib/mail.local [-f sender] [-d] recipient DESCRIPTION
mail.local reads the standard input up to an end-of-file and appends it to each user's mail file (mailbox). This program is intended to be used by sendmail(1M) as a mail delivery agent for local mail. It is not a user interface agent. Messages are appended to the user's mail file in the /var/mail directory. The user must be a valid user name. Each delivered mail message in the mailbox is preceded by a "Unix From line" with the following format: From sender_address time_stamp The sender_address is extracted from the SMTP envelope address (the envelope address is specified with the -f option). A trailing blank line is also added to the end of each message. The mail files are locked with a .lock file while mail is appended. The mail files are created with mode 660, owner is set to recipient, and group is set to mail. If the ``biff'' service is returned by get- servbyname(3SOCKET), the biff server is notified of delivered mail. This program also computes the Content-Length: header which will be used by the mailbox reader to mark the message boundary. OPTIONS
The following options are supported: -f sender Specifies the "envelope from address" of the message. This flag is technically optional, but should be used. -d Specifies the recipient of the message. This flag is also optional and is supported here for backward compatibility. That is, mail.local recipient is the same as mail.local -d recipient. -l Turn on LMTP mode. -r from Specify the sender's name (for backward compatibility). -7 Do not advertise 8BITMIME support in LMTP mode. -b Return a permanent error instead of a temporary error if a mailbox exceeds quota. OPERANDS
The following operand is supported: recipient The recipient of the mail message. ENVIRONMENT VARIABLES
TZ Used to set the appropriate time zone on the timestamp. EXIT STATUS
The following exit values are returned: 0 Successful operation. >0 An error occurred. FILES
/tmp/local.XXXXXX temporary files /tmp/lochd.XXXXXX temporary files /var/mail/user_name user's mail file ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWsndmu | +-----------------------------+-----------------------------+ SEE ALSO
mail(1), comsat(1M), sendmail(1M), getservbyname(3SOCKET), attributes(5) SunOS 5.10 11 Apr 1997 mail.local(1M)
All times are GMT -4. The time now is 05:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy