Problems with using uuencode on RHEL to send mail attachment - email

I have a unique situation where I'm going from an AIX platform to RHEL for a vendor supported application. Within the application, I can send a command (limited to the amount of characters I can send) that will email me results of a print job.
To do this in AIX, I'm passing the following command:
uuencode temp.txt | mail -s "test" email#address.com
This sends standard output to the email as an attachment named temp.txt. Temp.txt doesn't exist on the AIX server.
I have downloaded the rpm for uuencode for Linux, but it doesn't work in the same fashion. It sends an email with what looks like garbage (could be missing MIME header).
I'm looking for a similar command. To simulate outside of the application, I use the following in AIX:
echo "testing mail" | uuencode temp.txt | mail -s "test" email#address.com
I know mailx -a <filename> would work if I had a filename, unfortunately I'm working with standard output vs a file.
Any help will be appreciated.

Related

uuencode attaches file at the beginning of the mail body

I am using below code in AIX and the problem is it attaches the file at the very beginning of the mail, I want to attach the file after the mail body.
(uuencode <filepath> <filename-in-mail>;cat <body-of-the-mail-file>) | mailx -s "Subject" -r <sender-address> <multiple-receiver-addresses>
Any thoughts?, On AIX only uuencode is working, base64 or any other command doesn't work.
I tried a lame change in the code uuencode cat <body-of-the-mail-file>;<filepath> <filename-in-mail> but it gave error

Using mailx command for sending mail with attachment and messagebody in UNIX

i have been trying to send an email from my script which is generating an excel and then zipping it. i want to send this zipped file as an attachment along with a message body, but no success.
i have been using the below code:
1) uuencode inputFileName OutputFileName | mailx -s "Report" abc#gmail.com -- -f abc#gmail.com
this commandline is successfully sending my attachment
2) uuencode inputFileName OutputFileName | mailx -s "Report" abc#gmail.com -- -f abc#gmail.com < MessageBody.txt
with this commandline, i am trying to send the same attachment with mail body fetched from external file MessageBody.txt, but it is then sending the mail only with mail body, and NO attachment.
You are giving two different sources for stdin. At the beginning of the line you are taking stdin from stdout of uuencode but at the end of the line you are taking stdin from the file MessageBody.txt.
Instead you could try the following:
uuencode inputFileName OutputFileName | cat - MessageBody.txt | mailx -s "Report" abc#gmail.com -- -f abc#gmail.com
regards Henrik

Mailx with uuencode not sending multiple attachments with a proper email body on Suse Linux

This particular piece of code below worked correctly on AIX
( echo "mailbody";
uuencode a.txt 'arenamed.txt';
uuencode ab.txt 'abrenamed.txt';
uuencode abc.txt 'abcrenamed.txt';
uuencode abcd.txt 'abcdrenamed.txt'; ) | mailx -s "$subject" $emailaddress;
But on Linux, any occurrence of uuencode is printing begin 644 blocks in the body of the email viewed on Outlook 2010.
begin 644 abc.txt
5:F%H<V1L:G-A"F%S9&MJ87-J9#L*
`
end
I have tried, using different variations of ( echo $body ; uuencode filename filenamechanged ) with echo first, uuencode later and vice versa but it doesn't help.
I would have used "mail -a" but I want to rename files which are emailed, so, was looking at uuencode.
Any suggestions other than using sendmail/mutt here?
This is what worked
(echo "Subject: $Mail_Subject";
echo "To:$Mail_List";
echo $Mail_Body;
uuencode $LOG_DIR/FileName1 'AttachmentDisplayName1';
uuencode $LOG_DIR/FileName2 'AttachmentDisplayName2') | sendmail -t $Mail_List
Hope this helps anyone who is looking for this kind of issue.

How does PHP's `mail` work?

PHP's mail function seems to deliver mail on a clean system, with no apparent configuration done by the administrator or webmaster (no SMTP configuration in php.ini, etc.). How does the mail function deliver mail to a remote server?
On *nix it invokes the sendmail binary, which then uses the mail configuration to route the email. On Windows, it sends to a SMTP server. In both cases the sysadmin sets up the mail system.
You can detect how it works as below.
First method
$ ltrace php -r "mail('tester#127.0.0.1', 'Test', 'Hello world');" 2>&1 | grep sendmail
memcpy(0x095ea168, "sendmail_from", 14) = 0x095ea168
memcpy(0x095ea1e0, "sendmail_path", 14) = 0x095ea1e0
popen("/usr/sbin/sendmail -t -i ", "w") = 0x0977c7c0
From the results of the above command can be seen that the popen() function opens the process of /usr/sbin/sendmail -t -i.
$ ls -l /usr/sbin/sendmail
... /usr/sbin/sendmail -> exim4
So sendmail is the symbolic link to exim4 and hence sendmail -t -i invokes exim4 -t -i.
And in the manual page of exim4 you can read about these options -t -i:
$ man exim4 | grep ' -t -i'
-ti This option is exactly equivalent to -t -i. It is provided for compatibility with Sendmail.
Second method
Install snoopy and run:
# grep snoopy /var/log/auth.log | tail
... php -r mail('tester#127.0.0.1', 'Test', 'Hello world');
... /usr/sbin/sendmail -t -i
... /usr/sbin/exim4 -Mc 1YxxYn-0006a7-Nw
... /usr/sbin/exim4 -t -oem -oi -f <> -E1YxxYn-0006a7-Nw
... /usr/sbin/exim4 -Mc 1YxxYn-0006aB-Oj
The results of the above command show the sequence of the commands which were performed.
mail() uses sendmail, that uses DNS to find MX record of target domain and delivers there directly. thats it.
and since destination server probably does not know your ip address, especially if it is NATed it may be marked as spam.
you can modify your config to use different (legit ad known) smtp server to act as intermediary.
It's really not that reliable, actually, unless the underlying sendmail or something is properly configured.
Amazon SES has better servers than whatever server you're using and gets mail there more times than with mail().
The real reason you shouldn't use mail() is because your server's IP address is probably completely unknown to mail services such as GMail, Yahoo, etc, and there is a higher chance it will get marked as spam. Why does it get marked as spam? Because mail() is very easy and simple to exploit for spam purposes.

cron: sending output to file then EMAILing file to me

I am writing a series of cron jobs. I want each task to log its output to file, and then I want the contents of the file mailed to me at say me#somewhere.com
I think logging the output to file can be done using simple pipe redirection like this:
30 0 * * * /path/to/script1 > task1.log
30 1 * * * /path/to/script2 > task2.log
However, I am not sure how to mail the files (or simply their contents) to me in seperate emails to me#somewhere.com
Also, is there a way to dynamically create the log file names, based on the date, so that the log names would be something like %Y%m%d.task1.log ?
Where the prefix is the date ?
I am running on Ubuntu 10.0.4 LTS
If your system has a working /usr/bin/sendmail (doesn't have to be sendmail sendmail, most mail servers provide a /usr/bin/sendmail wrapper script) then you can use the mail(1) utility to send mail:
echo "hello world" | mail -s hello me#example.com
mail(1) is pretty primitive; there's no MIME file attachments, you're stuck with plaintext.
If mutt(1) is installed, you can use MIME to attach files:
echo "hello world" | mutt -a task*.log -- me#example.com
As for giving the logfiles dates:
$ echo "hi" > $(date "+%Y%m%dlog.txt")
$ cat 20110328log.txt
hi
$
So, try this:
30 1 * * * /path/to/script2 > $(date "+\%Y\%m\%dlog.txt") && mutt -a $(date "+\%Y\%m\%dlog.txt") -- me#example.com