I have a CentOS server which does not have the mail client. I do not have sudo access to install it or to install mutt.
What may be the best alternative that I can use to send myself an email to notify a failure/success of a process that I run on this server?
Maybe you could write a quick script in Python doing the job. Python is surely already installed, and you will be able to do the whole job with the standard library. Here is a small example as a starting point: https://docs.python.org/2/library/email-examples.html
Regards.
Try this out:
/bin/mail -s "Enter Subject Line here" -a /home/.../whateverFileYouWantAttached "you#YourEmailAddress" < /home/me/textBody.letter
Related
I am using the "mail" command in Linux shell to send an email when programmatically prompted to do so. I am using
mail -s 'subject' recipient#theirhost.com <<< 'Email body'
to send it at present, but this does not include a sender address. Instead, the system uses the account name as the sender address. I've seen the claim that "-aFrom:myname#myhost.com" should work, but -a is being interpreted as an attachment attempt, not a header change. This results in the error: "From:Mynamemyname#myhost.com: No such file or directory". I've also seen a claim that this works:
-r "from#fromserver.com"
But the OS doesn't even know what that means, in my case.
Is there a way to make this work without additional software? I don't need a from name, but a from address would be very helpful.
Note: let's consider ssmtp, mutt, and other such add-on software unavailable. Attempting to install and use such software would be problematic.
Thank you!
Edit 1: I'm not certain how to check what version of "mail" I have. With some difficulty, I got it to spit out the usage, which is as follows.
-T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users
Never mind, I got it. "-r" can actually work.
I successfully used:
echo "This is the message body" | mail -s "This is the Subject" -r "FromName<fromAddress#example.com>" recipientName#example.com
It looks like karakfa was onto something also, as I do have mailx available to me also, but it looks like I won't be needing that for this use case.
Thank you!
Recently we have migrated Unix OS to new flavor. Since then we couldn't able to send mails. I think we are missing some configuration, Could someone help in resolving the issue.
Command: echo "" | mutt -s "subject" -i /tmp/test.txt -a /tmp/test.txt xxx#gmail.com
Error: Can't stat xxx#gmail.com: No such file or directory
xxx#gmail.com: unable to attach file.
Current OS: Oracle Linux Server release 7.1
Mutt 1.5.21 (2010-09-15)
Please let me know what would be the issue.
Take a look at the man page. It states, that -a takes a list of arguments, which need to be terminated by --.
I have been trying to automate the setup process for pi hole on a raspberry pi. I am relatively new to bash and am unable to figure out how to automate the setup process once the terminal gui for the program begins.
this is what I have so far
#!/bin/bash
pihole -r
echo "waited"
$SHELL
So I reiterate back to my question, how do I automate the task of choosing and entering the option in the terminal gui of the pihole program? Any help would be greatly appreciated.
There's already a script that should be able to do it for you ("Pi-hole Automated Install")
To execute it you'd do:
curl -L install.pi-hole.net | bash
unfortunately it's too big to post here, so you'll want to grab it
here:
↳ Github : Pi-hole Automated Install
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I know there is the command mail in linux to send emails via command line. How can I send an simple email with one line from the terminal though?
For example:
mail user#gmail.com [subject] [body]
And have the email sent without any confirmation or prompts to the user?
The reason is, I want to send a brief message via email to myself when a specific event happens in a java program. The idea is that I will use Runtime.getRuntime()… etc. to send the mail command from my java program.
I used cron to do something similar in the past, but the current implementation doesn't use cron, so I need to try this out instead.
mail can represent quite a couple of programs on a linux system. What you want behind it is either sendmail or postfix. I recommend the latter.
You can install it via your favorite package manager. Then you have to configure it, and once you have done that, you can send email like this:
echo "My message" | mail -s subject user#gmail.com
See the manual for more information.
As far as configuring postfix goes, there's plenty of articles on the internet on how to do it.
Unless you're on a public server with a registered domain, you generally want to forward the email to a SMTP server that you can send email from.
For gmail, for example, follow
http://rtcamp.com/tutorials/linux/ubuntu-postfix-gmail-smtp/
or any other similar tutorial.
echo "Subject: test" | /usr/sbin/sendmail user#domain.com
This enables you to do it within one command line without having to echo a text file. This answer builds on top of #mti2935's answer. So credit goes there.
You can use an echo with a pipe to avoid prompts or confirmation.
echo "This is the body" | mail -s "This is the subject" user#gmail.com
For Ubuntu users: First You need to install mailutils
sudo apt-get install mailutils
Setup an email server, if you are using gmail or smtp. follow this link. then use this command to send email.
echo "this is a test mail" | mail -s "Subject of mail" username#domain.com
In case you are using gmail and still you are getting some authentication error then you need to change setting of gmail:
Turn on Access for less secure apps from here
You can also use sendmail:
/usr/sbin/sendmail user#domain.com < /file/to/send
You can install the mail package in Ubuntu with below command.
For Ubuntu -:
$ sudo apt-get install -y mailutils
For CentOs-:
$ sudo yum install -y mailx
Test Mail command-:
$ echo "Mail test" | mail -s "Subject" youremail#domain.com
Sending Simple Mail:
$ mail -s "test message from centos" recipient#example.com
hello from centos linux command line
Ctrl+D to finish
I have setup an SSH tunnel to my mail server as follows:
ssh -o ServerAliveInterval=60 -f me\#mydomain.com -L 63110:mail.mydomain.com:110 -N
ssh -o ServerAliveInterval=60 -f me\#mydomain.com -L 63325:mail.mydomain.com:25 -N
I can send/receive mail for a while, but after a period of inactivity, my mail client reports that it doesn't get a valid greeting from the mail server.
I have a perl script that checks every minute to make sure that the ssh tunnel is running (via ps) and that the port is open (using IO::Socket::PortState qw(check_ports)), but I would like to check whether or not I get a valid greeting as well.
What would be the best way to do this either in perl or a shell script (running Ubuntu 12.04)?
To answer the question, notwithstanding the setup of the OP, THE tool to use is swaks aka the Swiss Army Knife of SMTP. You can get it from here: http://jetmore.org/john/code/swaks/
Typically to test your smtp you would use a command like this: swaks --server mail.example.com --from ben.holness#example.com --to ben.holness#somewhere.example.com
It will then show you all the dialogue between the smtp client and the server, making it really easy to pinpoint the source of possible problems.