LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-04-2020, 11:16 PM   #1
Indranil.Nag
LQ Newbie
 
Registered: Jan 2020
Posts: 6

Rep: Reputation: Disabled
Post How to send attachments using mailx command


Hello Members,

I am new to linux and i am using RHEL (Linux 2.6.18-371.el5). I have a query: How to send attachments using mailx command?

i have tried:

i. mailx -s "subject" -a "attachment" "recipient" command.
ii. echo|mailx -s ""subject" -a "attachment" "recipient"
iii. uuencode filename | mailx -s "subject" "recipient"

none of these worked for me.
I have gone through different threads in this forum but could not find anything that fits my query.
Could you guys please help me out or maybe point me towards right discussion.
Thanks!

Regards,
Neel
 
Old 02-05-2020, 12:26 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
I tried
Code:
echo|mailx -s ""subject" -a "attachment" "recipient"
with a 112 bytes binary attachment, and it worked for me. That is, I was able to send the message and found it, with attachment, in the recipient's mailbox. The mailbox contains:
Code:
--=_5e3986b3.qw/Y57zQx0O/wlmMccHS33NJF8Zu/hiF5M62F+McPVrz6T3a
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="student"

AgA4AAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAACADgAAgAAAOkDAAC5BwAANwIAAAAAAACA6oIrAAAAAEgCAAAAAAAA/82sAAAAAAAAiAAA
AAAAAA==
EDIT: This was on Centos 8, not RHEL 5. Perhaps your version of mailx works differently.
 
Old 02-06-2020, 02:00 PM   #3
Indranil.Nag
LQ Newbie
 
Registered: Jan 2020
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks berndbausch..
But it does not work.
Need other ideas.
 
Old 02-06-2020, 02:04 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Indranil.Nag View Post
Thanks berndbausch..
But it does not work.
Need other ideas.
Then you need to provide details, such as what you're trying to attach, version of RHEL, what mail system, results of the tests, etc. We need more details than "does not work".

Depending on what you're trying to send, you may have to use mime64, break it up into a multi-part message, etc., but we don't know. And have you contacted Red Hat support, since you're PAYING FOR RHEL, RIGHT??
 
1 members found this post helpful.
Old 02-06-2020, 04:38 PM   #5
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by Indranil.Nag View Post
i. mailx -s "subject" -a "attachment" "recipient" command.
According to the man page the "attachment" has to be a FILE:
Quote:
-a file
Attach the given file to the message.
Did you do that?
 
2 members found this post helpful.
Old 02-07-2020, 03:00 PM   #6
Indranil.Nag
LQ Newbie
 
Registered: Jan 2020
Posts: 6

Original Poster
Rep: Reputation: Disabled
Yes ehartman, it'a basic txt file.
 
Old 02-07-2020, 03:03 PM   #7
Indranil.Nag
LQ Newbie
 
Registered: Jan 2020
Posts: 6

Original Poster
Rep: Reputation: Disabled
@Tb0ne, i am trying to send a basic txt file using mailx. It uses smtp mail services.
 
Old 02-07-2020, 03:04 PM   #8
Indranil.Nag
LQ Newbie
 
Registered: Jan 2020
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ehartman View Post
According to the man page the "attachment" has to be a FILE:


Did you do that?
Yes ehartman, it'a basic txt file
 
Old 02-07-2020, 03:05 PM   #9
Indranil.Nag
LQ Newbie
 
Registered: Jan 2020
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Then you need to provide details, such as what you're trying to attach, version of RHEL, what mail system, results of the tests, etc. We need more details than "does not work".

Depending on what you're trying to send, you may have to use mime64, break it up into a multi-part message, etc., but we don't know. And have you contacted Red Hat support, since you're PAYING FOR RHEL, RIGHT??
@Tb0ne, i am trying to send a basic txt file using mailx. It uses smtp mail services
 
Old 02-07-2020, 03:13 PM   #10
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by berndbausch View Post
EDIT: This was on Centos 8, not RHEL 5. Perhaps your version of mailx works differently.
Yes. OP what does your man mailx say, specifically about how to attach files?

Also, as has been asked, what exactly do you mean by "doesn't work"?
Are there any errors indicated in the maillog?
 
1 members found this post helpful.
Old 02-07-2020, 04:32 PM   #11
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by Indranil.Nag View Post
Hello Members,

I am new to linux and i am using RHEL (Linux 2.6.18-371.el5). I have a query: How to send attachments using mailx command?

i have tried:

i. mailx -s "subject" -a "attachment" "recipient" command.
ii. echo|mailx -s ""subject" -a "attachment" "recipient"
iii. uuencode filename | mailx -s "subject" "recipient"

none of these worked for me.
All of those commands look a little "off" to me. Are you creating a message body at all? Or did you leave that off for brevity? I'd expect to see something like:

Code:
echo "Detach this" | mailx -s subject -a attach.txt someone@remotehost
or
Code:
mailx -s subject -a attach.txt someone@remotehost < /dev/null
if you don't need/want to include a message body.

Use "tail -f" on the /var/log/mail log file -- or "journalctl -af" (or similar) -- and watch what happens when you attempt to send the email with the attachment. Is it being accepted by the remote user's mail system? Or rejected?

Is your recipient able to receive attachments at all? Or are you sending one that's very, very large?
 
Old 02-08-2020, 12:53 AM   #12
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by Indranil.Nag View Post
Yes ehartman, it'a basic txt file
Pure ASCII, or in any other text encoding (like ISO-8859 or utf/ucs)?
That is: is it 7-bits characters only.
Otherwise: does your version of mailx know how to encode 8-bits byte (essentially binary) files into a mail?

In essence smtp is setup to use 7-bits chars only because of possible restrictions on "systems on the way".
 
Old 02-08-2020, 09:29 AM   #13
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Indranil.Nag View Post
@Tb0ne, i am trying to send a basic txt file using mailx. It uses smtp mail services
Yes, ALL Mail systems use SMTP...that doesn't tell us anything. It's like saying "I use a computer for email"...very true, but kind of a given. To be more clear:
  • Are you using postfix or sendmail on the back side of things??
  • What version of RHEL?
  • What you've ACTUALLY SEEN as the results of your tests. Does anything come through? If so, what? What do you see in the mail log files???
  • Have you contacted RHEL support, since you're PAYING FOR RHEL????
If it's nothing but a text file, doing:
Code:
cat text-file-name | mailx -s "Subject Line" user@domain.com
..is all you need. AGAIN, you will need some sort of relay host set up further upstream to route the message, but you've still not said anything about your environment. With no relay host or any sort of configuration on your server to process email, it's not going anywhere, and you've not provided any information we've asked for, other than saying it's a 'text file', and 'it doesn't work'. We can't guess.
 
  


Reply



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
[SOLVED] "Snorkeling on an empty pipe": error in S-mailx (mailx 4.19.11) RandomTroll Linux - Software 0 11-30-2018 10:45 PM
[SOLVED] mailx attachments for Outlook 2007 keirvt Linux - Software 2 12-17-2016 01:47 PM
[SOLVED] Sending Multiple Attachments using MAILX metallica1973 Linux - Server 1 11-28-2011 02:27 PM
TO ANYONE USING MAILX (mailx 12.1). stf92 Linux - Software 22 07-08-2010 09:44 PM
Sending attachments using mailx wolfman423 Linux - Newbie 0 10-14-2005 08:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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