LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Sendmail (https://www.linuxquestions.org/questions/linux-software-2/sendmail-4175478656/)

T-Dub116 09-26-2013 11:43 AM

Sendmail
 
I am trying to get a log file sent to my e-mail from my Linux RH server.

I run thing command
cat smtest.txt | sendmail -t
smtest.txt:
to : *******@gmail.com
cc : *****@foodconnex.com
from : Your server name
subject : Test mail

TESTING 1 2 3 sendmail!!

How can I send an attachment with this command or somehow cat the file into smtest.txt where the body is.

I am open to other ideas, if there is a better sendmail command to run please let me know!

Thanks ahead of time!

TDUB

bathory 09-27-2013 02:36 AM

Hi,

You can use mutt for the same:
Code:

mutt -s "Subject" recipient@domain.com -a attachment.file < message-body.txt
Regards

eklavya 09-27-2013 04:59 AM

Above post is absolute way to send attachments from command line. But if you want to know another way, try uuencode command to send emails with attachments.
Take a look at this.
http://www.cyberciti.biz/faq/howto-u...l-attachments/

If you want to know more about these two, take a look at
http://www.shelldorado.com/articles/...tachments.html

Basher52 09-27-2013 05:58 AM

I can vote for uuencode, have used that the last couple of years :)

T-Dub116 09-27-2013 08:04 AM

Quote:

Originally Posted by bathory (Post 5035766)
Hi,

You can use mutt for the same:
Code:

mutt -s "Subject" recipient@domain.com -a attachment.file < message-body.txt
Regards




I have a log called ai.log, so how would I attach that? Also what is in attachment.file and message-body.txt?

mutt -s "AI Log" *******@gmail.com -a ????????????

bathory 09-27-2013 08:34 AM

Quote:

Originally Posted by T-Dub116 (Post 5035902)
I have a log called ai.log, so how would I attach that? Also what is in attachment.file and message-body.txt?

mutt -s "AI Log" *******@gmail.com -a ????????????

You should attach the logfile after the -a switch.
In message-body.txt you can put some text you want your recipient to read. If don't to, replace it with /dev/null
Code:

mutt -s "AI Log" *******@gmail.com -a ai.log < /dev/null

SAbhi 09-27-2013 09:26 AM

so found it searching for a simple solution...something like this could help you:

Code:

( echo "to: trail@somewhere.com"
  echo "from: s64110@elsewhere.com"
  echo "subject: sending file.jpg"
  echo "mime-version: 1.0"
  echo "content-type: multipart/related; boundary=xxxRANDOMSTRINGxxx"
  echo
  echo "--xxxRANDOMSTRINGxxx"
  echo "content-type: text/plain"
  echo
  echo "Body of the message goes here"
  echo "Here is file.jpg for your viewing pleasure"
  echo
  echo "--xxxRANDOMSTRINGxxx"
  echo "content-type: image/gif; name=file.jpg"
  echo "content-transfer-encoding: base64"
  echo
  openssl base64 < /tmp/file.jpg ) | sendmail -t -i

or using uuencode type this in place of openssl, define attachement as $ATTACH:
Code:

uuencode -m $ATTACH $(basename $ATTACH)
) | /usr/sbin/sendmail -t -i


T-Dub116 09-27-2013 09:43 AM

Quote:

Originally Posted by bathory (Post 5035913)
You should attach the logfile after the -a switch.
In message-body.txt you can put some text you want your recipient to read. If don't to, replace it with /dev/null
Code:

mutt -s "AI Log" *******@gmail.com -a ai.log < /dev/null


I run the command I found before
cat smtest.txt | sendmail -t

vi smtest.txt
to : *******@gmail.com
from : Your server name
subject : Test mail

I receive the e-mail,

but when I run
mutt -s "AI Log" ******@gmail.com -a ai.log < body.txt

I do not receive any e-mail

bathory 09-27-2013 03:14 PM

Quote:

but when I run
mutt -s "AI Log" ******@gmail.com -a ai.log < body.txt

I do not receive any e-mail
So, check the logs (usually /var/log/maillog) to see what happens

sag47 09-30-2013 02:30 PM

Quote:

Originally Posted by T-Dub116 (Post 5035902)
I have a log called ai.log, so how would I attach that? Also what is in attachment.file and message-body.txt?

mutt -s "AI Log" *******@gmail.com -a ????????????

When in doubt, read the man page and learn the options you're given. You should be doing that before running any command off of an internet website or example. It's a simple matter of security/integrity for your own system.

Code:

man mutt

T-Dub116 10-02-2013 04:02 PM

2 Attachment(s)
echo cat ai.log | mailx -s "Simple Test" *********@gmail.com

I check my E-mail and the Body is empty (simple sendmail 1)


But in the Header it has the beginning of the file
just as if I were to vi or cat the file out (simple sendmail 2)

vi ai.log
PROGRESS Version 9.1E as of Tue Oct 12 14:40:19 EDT 2004

After-image dates for this after-image file: #etc...

so the cat command is working, it just isn't putting it in the body of the email

but when I do this:
echo "tester" | mailx -s "Simeple Test" ***********@gmail.com

tester - shows up in the body!!

Any body now how I can get whats inside ai.log to show up into the body using this command or get ai.log to be sent as an attachment?

bathory 10-03-2013 02:01 AM

Hi,

You don't use echo and cat together. Just cat the logfile into the mailx command:
Code:

cat ai.log | mailx -s "Simple Test" *********@gmail.com
Another way is to redirect the logfile into mailx:
Code:

mailx -s "Simple Test" *********@gmail.com < ai.log
Regards

T-Dub116 10-03-2013 07:40 AM

Quote:

Originally Posted by bathory (Post 5039063)
Hi,

You don't use echo and cat together. Just cat the logfile into the mailx command:
Code:

cat ai.log | mailx -s "Simple Test" *********@gmail.com
Another way is to redirect the logfile into mailx:
Code:

mailx -s "Simple Test" *********@gmail.com < ai.log
Regards

When I just cat

cat ai.log | mailx -s "Simple AI" ************@gmail.com
#I do not get any e-mail

Also when I do the redirect:
mailx -s "Simple AI" **********@gmail.com < ai.log

I do not get an email either, it does come back saying...

you have new mail in /var/spool/mail/root


.

bathory 10-03-2013 08:04 AM

Quote:

I do not get an email either, it does come back saying...

you have new mail in /var/spool/mail/root
Check the logs (/var/log/maillog) to see what happens
If you don't get any mail, but mail has left your server, chances are that's it's finished into the spam folder

T-Dub116 10-03-2013 01:08 PM

1 Attachment(s)
I was able to tail ai.log to my email

(echo From: Blue_Star_1 [********@********]; echo Subject: Blue_Star_1 ; echo To: Foodconnex ; tail /appl/ai/ai.log) | sendmail `cat /appl/ai/recipients-list`

But the problem now is it is coming in as an "unknown sender" which then it keeps dumping into my spam folder. I have the from but it doesn't seem to be looking at that.

Does anyone have an idea with the command above so when my gmail gets the e-mail the from is from somewhere and not unknown sender?


All times are GMT -5. The time now is 05:05 PM.