Use mail command in terminal to send emails and specify From address - email

I have tried to send thousands of emails through running a csh script to execute the "mail" command. But all my emails were blocked by the recipient. I was told that the blocking reason is because of the workstation domain (kichisatoru#Sky.local), which is not a real domain (e.g. xx#gmail.com). How can I fix this issue, so the recipient can receive my emails in the standard way?
My csh:
#!/bin/csh
foreach eml (`ls *.eml`)
mail recipient#edu < $eml
echo $eml sent...
end

My problem is fixed! I have found a very detailed manual online http://www.developerfiles.com/how-to-send-emails-from-localhost-mac-os-x-el-capitan/

Related

Logrotate encryption before mailing

I use logrotate that sends me logs on a regular basis. My server is a VPS running Postfix as an outgoing-only SMTP server.
I would like all the mailed logs (which Logrotate sends) to be encrypted with PGP or S/MIME. How can I do that?
I searched for logrotate mail encryption, but couldn't find any. Therefore, I'm thinking that I can pass "nomail" command in logrotate config, but then add in the "postscript" a script to first encrypt the mail and then send.
So, is there a better way to encypt logrotate mail with PGP? Or that's what I need to do? I would appreciate any advise or an example of such a script.
Also, I'm not considering to use TLS as there are possible ways to bypass it in the SMTP server. And I would rather rely on encryption of individual messages.
Thanks!
Edit:
Here is my script I'm using for custom email sending(Without GPG for now):
#!/bin/bash
read MSG
echo $MSG | mail -s $1 $2
But when I force rotate with logrotate --mail=loggpg.sh --force /etc/logrotate.d/ufw I keep getting error about uncompression, do I need to manually uncompress it? Or there is smth wrong with the script?
Error I get:
error: mail command failed for /var/log/ufw.log.5.gz
error: uncompress command failed mailing /var/log/ufw.log.5.gz`
You can execute logrotate with --mail command line option. It will allow you to use your own shell/perl/python script to send email instead of default /bin/mail -s.
man logrotate
OPTIONS
...
-m, --mail
Tells logrotate which command to use when mailing logs. This command should accept two arguments: 1) the subject of the message, and
2) the recipient. The command must then read a message on standard input and mail it to the recipient. The default mail command is
/bin/mail -s.

How to send mail from zimbra command line

I am vikas. i am looking a command that can send mail from zimbra mail-store server to external world. but as i checked in zimbra not getting Any program that have role of sending mails. that is why i am relay email through Zimbra MTA server. now i am going to use below command but still getting variable error.
awk 'BEGIN{print "Subject:test mail!\nFrom:Mailadmin <admin#knowledgelinux.com>"}{printf("%s\015\n", $0)}' $message file-name=/test.txt | sendmail -t "mail#knowledgelinux.com"
awk: command not found
The instructions here worked for me:
vim /etc/logwatch/conf/logwatch.conf
Relevant lines to be replaced:
Output = mail
MailTo = root_all#your.domain
MailFrom = Logwatch#your.domain
mailer = "/opt/zimbra/common/sbin/sendmail -t"
Zimbra uses a modified version of sendmail.
The Zimbra MTA uses a modified postfix daemon. You should be able to just use the command mail:
cat *messagefilename* |mail -r *fromaddress* -s *Subject* *recipient-list*
As long as the Zimbra MTA is running on the machine in question this should work.

Not able to send e-mail using MUTT

I have set the from: email-id in .muttrc. I am using the following command to send an e-mail from command-line:
echo "<html><body><b>BOLD</b></body></html>" | mutt -e "set content_type=text/html" -s "HTML" -- xyz#gmail.com
I am able to send e-mail from only my home internet. If I try to send from any other network, it doesn't go. How should I fix this to be able to send e-mail from any network? What all changes are supposed to be made?

Can we trigger a perl script in unix by sending a mail

I want to know if we can trigger a perl script in unix through a sending a mail.
basically the script should check the incoming mail then trigger the perl script.
Also can some1 out on setting the mail access like reading and saving mail on my unix home.
-Thanks
There are two basic approaches you can take.
Configure your SMTP server to run incoming email through your script. Procmail is the usual tool for choice for this.
Poll (by using cron, or writing your script as a daemon) your IMAP/POP server/Maildir/Mbox/etc.
The former is usually the better option.
You can hack it like this:
inotifywait -m /var/mail/$USER | grep --line-buffered MODIFY | while read _unused_; do
#your perl script here
done
Explanation: It monitors /var/mail/$USER for changes & prints events on stdout. On every MODIFY event, it will trigger the script.
Note: This will work only for unix mails on localhost. Not on external server.
Known bugs:
A mail read activity will also trigger the script.
You can keep polling (unix) mail for any new mails.
while true; do
echo "\nq" | mail >/tmp/new_mail 2>&1 && /path/to/your/perl_script.pl arg1 arg2 ...
sleep 60
done
If you want, you can use contents of /tmp/new_mail in your perl program. If you don't need it, you can redirect mail output to /dev/null instead.

mail command of unix

I am using the mail command of unix in a perl script. I specify the 'to', 'cc', 'subject' and 'body' of the mail. I do not specify the from address. Where is the from address picked from? Pls help
There are portable libraries for handling email as daxim and David W mention, but if you want a quick fix, this works under linux if your mail command uses bsd-mailx (as it does on my machine)...
#!/usr/bin/env perl
$BODY = "Hello self";
$RECIPIENT = "destination\#email.local";
$FROM = "mike\#localhost";
$SUBJECT = "some subject here";
$CMD = qq(echo "$BODY" | mail -a "From: $FROM" -s $SUBJECT $RECIPIENT);
exec($CMD);
If you have more questions about the unix mail command, try man mail from your shell prompt.
The mail command on most system nowadays is Heirloom mailx. It claims compatibility with POSIX, so the information I give here should be good for any well-behaving mail command.
The From address is set by:
either the user#domain as returned by the appropriate POSIX system calls (see shell commands whoami and domainname -f for a different way to access them)
or set by the from environment variable
or set by the -r command line option (going to be deprecated?)
Obligatory Clippy: Hi! I see you are trying to send mail from Perl. Did you mean to use Email::Sender/Email::Simple instead?
Don't use the mail command linecommand! Use Net::SMTP.
The mail command may not even be configured on a particular system, and it won't work on Windows. Meanwhile, Net::SMTP is a standard Perl module that should be available on all systems.
Never used it before? Read the documentation and try it out. That's how you learn.