LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-26-2013, 11:43 AM   #1
T-Dub116
Member
 
Registered: Aug 2013
Location: Dolyestown
Posts: 88

Rep: Reputation: Disabled
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

Last edited by T-Dub116; 09-26-2013 at 02:11 PM.
 
Old 09-27-2013, 02:36 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

You can use mutt for the same:
Code:
mutt -s "Subject" recipient@domain.com -a attachment.file < message-body.txt
Regards
 
1 members found this post helpful.
Old 09-27-2013, 04:59 AM   #3
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
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

Last edited by eklavya; 09-27-2013 at 05:06 AM.
 
Old 09-27-2013, 05:58 AM   #4
Basher52
Member
 
Registered: Mar 2004
Location: .SE
Distribution: Arch
Posts: 396

Rep: Reputation: 22
I can vote for uuencode, have used that the last couple of years
 
Old 09-27-2013, 08:04 AM   #5
T-Dub116
Member
 
Registered: Aug 2013
Location: Dolyestown
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bathory View Post
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 ????????????
 
Old 09-27-2013, 08:34 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Originally Posted by T-Dub116 View Post
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
 
1 members found this post helpful.
Old 09-27-2013, 09:26 AM   #7
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 665

Rep: Reputation: Disabled
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

Last edited by SAbhi; 09-27-2013 at 09:32 AM.
 
Old 09-27-2013, 09:43 AM   #8
T-Dub116
Member
 
Registered: Aug 2013
Location: Dolyestown
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bathory View Post
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
 
Old 09-27-2013, 03:14 PM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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
 
Old 09-30-2013, 02:30 PM   #10
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Quote:
Originally Posted by T-Dub116 View Post
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

Last edited by sag47; 09-30-2013 at 02:32 PM.
 
Old 10-02-2013, 04:02 PM   #11
T-Dub116
Member
 
Registered: Aug 2013
Location: Dolyestown
Posts: 88

Original Poster
Rep: Reputation: Disabled
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?
Attached Thumbnails
Click image for larger version

Name:	simple sendmail 1.jpg
Views:	26
Size:	24.7 KB
ID:	13602   Click image for larger version

Name:	simple Sendmail 2.jpg
Views:	21
Size:	29.3 KB
ID:	13603  

Last edited by T-Dub116; 10-02-2013 at 04:06 PM.
 
Old 10-03-2013, 02:01 AM   #12
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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
 
Old 10-03-2013, 07:40 AM   #13
T-Dub116
Member
 
Registered: Aug 2013
Location: Dolyestown
Posts: 88

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bathory View Post
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


.

Last edited by T-Dub116; 10-03-2013 at 07:41 AM.
 
Old 10-03-2013, 08:04 AM   #14
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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
 
Old 10-03-2013, 01:08 PM   #15
T-Dub116
Member
 
Registered: Aug 2013
Location: Dolyestown
Posts: 88

Original Poster
Rep: Reputation: Disabled
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?
Attached Thumbnails
Click image for larger version

Name:	Blue Star Unknown Sender.jpg
Views:	23
Size:	20.5 KB
ID:	13615  
 
  


Reply

Tags
sendmail


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sendmail M4 configuration base directory /usr/share/sendmail-cf was not found eliassal Linux - Server 15 11-04-2010 01:09 AM
Sendmail config questions + Sendmail not reflecting changes to access db wbuik Linux - Networking 2 03-26-2009 05:02 AM
Sendmail ignores aliases with sendmail daemon stopped phavn Solaris / OpenSolaris 1 12-01-2008 02:50 PM
m4 sendmail.mc > sendmail.cf generate unwanted result on OpenSolaris johncsl82 Solaris / OpenSolaris 1 09-08-2008 11:25 PM
sendmail is not working & on $prompt the cmd sendmail hangs Pavan mahoorker Linux - Software 1 04-04-2006 03:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration