I'm receiving file hc.html as an attachment. But I wanted the output of hc.html as Body in Lotus Notes 8. I was using sendmail earlier and it was working fine for Outlook. In this new environment I cannot use sendmail. I can only use mailx.
Can anything can be done for this?
(cat body.txt; uuencode $OP $OP) | mailx -s 'Subject' xxx#yy.com
OP=/tmp/hc.html
Try this:
mailx -s "subject" emailaddress < $OP
Related
How to send some text in email along with the contents of the file, don't want to send file as an attachment? is it possible via mailx command?
mailx -s "Email log file" abc#mail.com <$log_file;
$log_file contents gets emailed but below doesn't work
echo "Comment: log contains last month report" | mailx -s "Email log file" abc#mail.com < $log_file
Needed output in email:
Comment: Log contains last month report
<All contents of $LOG_FILE as text>
Here is how you would do it:
echo "Comment: log contains last month report\n $(cat \$log_file)" | mailx -s "Email log file" abc#mail.com
The only thing "funny" is you'll have to escape that $ in the filename. You can also add more new lines \n if need be.
I'm running a bash script in cron to send mail to multiple recipients when a certain condition is met.
I've coded the variables like this:
subject="Subject"
from="user#example.com"
recipients="user1#mail.example user2#mail.example"
mail="subject:$subject\nfrom:$from\nExample Message"
And the actual sending:
echo -e $mail | /usr/sbin/sendmail "$recipients"
The problem is that only user2#mail.example is receiving the email. How can I change this so all the recipients receive the email?
NOTE: The solution has to be with sendmail, I'm using jailshell and it seems to be the only available method
Try doing this:
recipients="user1#mail.example,user2#mail.example,user3#mail.example"
And another approach, using shell here-doc:
/usr/sbin/sendmail "$recipients" <<EOF
subject:$subject
from:$from
Example Message
EOF
Be sure to separate the headers from the body with a blank line as per RFC 822.
Use option -t for sendmail.
in your case - echo -e $mail | /usr/sbin/sendmail -t
and add your recipient list to message itself like To: someone#example.com someother#nowhere.example right after the line From:.....
-t option means -
Read message for recipients. To:, Cc:, and Bcc: lines will be scanned for recipient addresses. The Bcc: line will be deleted before transmission.
to use sendmail from the shell script
subject="mail subject"
body="Hello World"
from="me#example.com"
to="recipient1#example.com,recipient2#example.com"
echo -e "Subject:${subject}\n${body}" | sendmail -f "${from}" -t "${to}"
For postfix sendmail, I am adding one line command useful for scripting
I had problem adding recipients in default position in the end of sendmail command in RHEL (Undisclosed Recipients) and piping echo command saved the day.
Option -f found from http://www.postfix.org/sendmail.1.html
Please note that syntax in echo is important, try echo to a file to check before attempting with sendmail.
echo -e "To:receiver1#domain1, receiver2#domain2 \nSubject:Subject of email \n\nBody of email.\n" | /usr/sbin/sendmail -f sender#domain -F sendername -it
I try send a mail with mail command, with the output of other command in the subject
subj="hello from $(hostname -s) $(date)"
echo "data" | mail -s $subj mail#mail
but I only get the first part of subject (hello from).
why?
You need to quote your subject, like this:
echo "data" | mail -s "$subj" mail#mail
If you don't quote it, the mail program will not know where your subject ends and will take the first "word" (hello) as the subject and everything else as an address.
In general, it is good practice to always quote your variables.
/youScriptOrOutput.sh | mail -s "Subject from host $(hostname -s) $(date)" my#email.com
I'm finding that a call to the mail command is causing a script to suspend without error. To close the script I have to ctrl-c or issue a kill command on the process id.
The pertinent section of the script is below:
EMAIL_TO="my#email.com"
if [ -f /www/archives/pdf/pdf_201207021048.tar ]; then
echo "file exists"
else
echo "file does not exist"
fi
echo "sending mail next..."
mail -s "pdfbackup" "$EMAIL_TO"
echo "mail sent?"
When running this, I'm seeing the text "sending mail next..." and nothing more. It never returns to prompt.
I can see the script is still in memory with ps -ax | grep myscript.sh.
I've tried using quotes around the subject and email, and again without. The same result is produced either way.
What am I doing wrong?
From man mail:
Sending Mail
To send a message to one or more people, mail can be invoked with arguments which are the names of people to whom the mail will be sent. You are then expected to type in your message, followed by a at the beginning of a line. The section below Replying To or Originating Mail, describes some features of mail available to help you compose your letter.
It's expecting a body of the message. Use <C-d> for newlines and end the message with a blank line and <C-d>. Alternatively you can supply the body and pipe to the command...
echo "This is the body" | mail -s "Subject" "recipient#example.com"
or
mail -s "Subject" "recipient#example.com" <<< "This is the body"
Or your can read the body from a file..
mail -s "Subject" "recipient#example.com" < body_in_file.txt
#!/bin/bash
MESSAGE="Line one. /n"
MESSAGE="$MESSAGE Line two. /n"
MESSAGE="$MESSAGE Line three."
echo $MESSAGE | mail -s "test" "example#example.com"
Is that how I should get each line, on its own line?
Use a heredoc.
mail -s "test" "example#example.com" << END_MAIL
Line one.
Line two.
Line three.
END_MAIL
Change:
echo $MESSAGE | mail -s "test" "example#example.com"
To:
echo -e $MESSAGE | mail -s "test" "example#example.com"
The heredoc advice is good, plus you might want to consider using mailx for which there exists a Posix standard or perhaps sendmail which will exist if the mailer is either sendmail or postfix. (I'm not sure about qmail.)
Unless using sendmail, it's also a good idea to set the MAILRC variable to /dev/null to bypass the user's configuration script, if any.