Save mail message as a file on Linux using sendmail - linux

I have an application running on several RHEL 5.8 systems which monitors and alerts (via email). I need to create a durable log of these alerts locally on each node.
I think the easiest way to do this would be to add a local email user to the alerts and then use mailbox settings or a script (if needed) to save each message on a local filesystem
I would settle for message body dumped to a text file (one file per email.)
It would be better if it could extract time, host, subject, & body as seperate fields for consumption by an open source log reader.
My systems are using sendmail 8.1 and I would prefer to stick with it, although I also have postfix 2.3.3 available.

As you reported your sendmail uses procmail as local mailer => create special OS user account (e.g. log_user) and use ~log_user/.procmailrc to instruct procmail to deliver messages to maildir folder.
~log_user/.procmailrc
# deliver ALL messages to ~/maillog/ maildir.
# see "man procmailex" for email sorting examples
:0
maillog/

Related

Send an alert when memory and cpu on linux VPS

I have a private linux vps and want to monitor it by sending email when memory or process usage is high.
Is there any free service to send email ? (solution like Sendinblue are requiring profesionnel account)
Other method to monitor vps are welcome too.
I've used HetrixTools and was satisfied with it. They have instructions for you to install an open source agent on your VPS which then sends data to your HetrixTools dashboard.
You can then set up alerts based on different criteria (like RAM or CPU usage) and also "Contact Lists" which include different services (like email and Telegram messages).
Whenever one of your criteria is met, you will receive a notification.
Disclaimer: I've no affiliation with HetrixTools.

Mautic is not processing the queue. Messages are in the spool/default folder

Mautic will not send my queued emails.
I have set up the cron jobs and they are running as expected. The cron job email report for the ":messages:send" cron job that runs every minute is always this...
Processing message queue
Messages sent: 0
Content-type: text/html; charset=UTF-8
I have messages in my queue, which I have sent via the Contacts Tab, by clicking on the contact name (myself) and then clicking on the Send Email button, just to send myself a test email.
In my configuration email settings I am using PHP Mail.
If I have the mail set to 'Send Immediately' it works fine. I get my test email instantly. But if I have it set to queue the message goes into my spool/default folder but when the cron job triggers it is not sent.
Things I have tried so far....
I deleted the cache folder contents
I checked to see if I have two versions of this file: SendChannelBroadcastCommand.php - I don't, I just have this file once, in the ChannelBundle/Command folder. It is not also in the CoreBundle/Command folder (as suggested by a similar post)
I deleted all of the queued messages in the spool/default folder, then sent some more... which are now sitting in the folder just like before.
Things that might be a factor?
The permissions for the file SendChannelBroadcastCommand.php is set to 644. I don't know if this is correct but assume it is.
When I open the SendChannelBroadcastCommand.php file in dreamweaver, it flags it with lots of syntax errors. I don't really know enough about code to determine if these are genuine errors or if Dreamwaever is just being a little too sensitive. I also don't know if this file in included inside another one that'd make those errors disappear if Dreamweaver could see the complete end result, but I thought it was worth a mention.
Things that I'm sure are not a problem
I'm certain that the cron job is set up correctly. It is running. And I receive the email reports (although I've turned those back off now as I don't want a report every minute)
I've seen this problem mentioned a few times on other forums but none of the solutions are working for me.
My Mautic installation is 2.14.0
My PHP is 7.0.31
Installation was via Softaculous on cPanel on a dedicated server hosted with Namecheap
Thank you in advance for any suggestions that I can try to fix this issue.
Steve.
Oh, in case you're wondering... I am using PHP Mail as Mautic would not connect to Amazon SES. For that I get the following error (which my hosting company was unable to help me fix, so I'm trying PHP mail)
Connection could not be established with host email-smtp.us-east-1.amazonaws.com [Connection refused #111] Log data: ++ Starting Mautic\EmailBundle\Swiftmailer\Transport\AmazonTransport !! Connection could not be established with host email-smtp.us-east-1.amazonaws.com [Connection refused #111] (code: 0)
++ Starting Mautic\EmailBundle\Swiftmailer\Transport\AmazonTransport !! Connection could not be established with host email-smtp.us-east-1.amazonaws.com [Connection refused #111] (code: 0)
Regarding your Amazon SES Connection refused #111] (code: 0) error, it is hard-coded in mautic to use port 2587 to connect to amazon ses, regardless of what port you put in the smtp port number. This is in Mautic 2.13.1 version. Make sure TCP 2587 in/out is open on your webserver firewall. This change solved that error message for me. Have not expierenced a queue error, sorry can't comment on that.
If your queue setup is perfect then there is one more thing is there to setup in cron level.
That is php /path/to/mautic/bin/console mautic:emails:send
This command is used to process queued emails for Mautic
Check this for more info https://docs.mautic.org/en/setup/cron-jobs
Due to this only the emails are not processing, if your queue setup is good.
Just add the command and try again, it will work.

convert rsyslog message format when forwarding messages with structured-data

My daemon uses libc syslog() call that logs messages in RSYSLOG_TraditionalFileFormat format. And, rsyslogd daemon running on the same host needs to forward all these messages to a remote log collector in RSYSLOG_SyslogProtocol23Format format.
Now I want to "piggy back" %STRUCTURED-DATA% to RSYSLOG_TraditionalFileFormat format (basically when my daemon will call syslog() it will specify structured data in square brackets). How can I specify incoming log message format (or template) in rsyslog.conf so that it would understand structured-data?
I understand that one of the solutions would be for my daemon to directly send message to /dev/log and change default log message format in rsyslog.conf. However, this does not seem right, because I want to keep the local log format the same.
It seems that it is impossible to solve this in an elegant way, because libc syslog() call uses /dev/log UNIX domain socket.
And rsyslog 8.8 and older uses hardcoded message parser for messages received over UNIX domain socket. See usespecialparser setting (http://www.rsyslog.com/doc/v8-stable/configuration/modules/imuxsock.html)
Another option to get this to work with the latest Ubuntu 15.04 that ships with rsyslog 7.4 would be to use UDP socket, but then I can't use libc syslog() anymore.

ftp mget does not show successful completion

I was using ftp and successfully connecting to the host.
Then I do
mget test.tar.gz
Even though it successfully test.tar.gz, I have to check the size of the file manually with ls -l command in the other terminal. Is there any way that mget or some other command will indicate to me that the transfer of the file is complete.
It depends a bit on the implementation of the FTP server, but in most cases you should receive something like
250 transfer complete.
250 basically is the return code for Requested file action okay, completed. while the text messages differ sometimes between servers.
In order to make sure you see all the return codes, run your ftp with -v, which enables verbose mode. This forces ftp (and many other linux ftp clients I know of) to show all responses from the remote server, as well as report on data transfer statistics.
A list of most server return codes can be found here.

Apache James - reduce message time in spool

I'm using a local Apache James 2.3.2 install for development and automated testing. It's configured to forward all incoming messages to a single address and to not relay emails outside:
<mailet match="All" class="Forward">
<forwardto>test#localhost</forwardto>
</mailet>
Everything works correctly: emails are accepted, placed in the spool directory, then finally moved to the inbox/test directory, from which they are then picked up by my automated tests for verification.
The only problem is, it can take anywhere between 10 and 60 seconds for those emails to be moved from the spool directory to the inbox/test directory, meaning the tests need to wait that long before retrieving them and doing their checks.
Is this something that can be configured otherwise? Or should I simply move to a different email server for testing purposes?
Thanks!
Not a direct answer to this question, but I've ended up switching to JES http://www.ericdaugherty.com/java/mailserver/ . You can configure how many SMTP and POP3 threads do the work as well as the frequency at which these threads pick up messages from the spool and try to send deliver them
# The server stores incoming SMTP messages on disk before attempting to deliver them. This
# setting determines how often (in seconds) the server checks the disk for new messages to deliver. The
# smaller the number, the faster message will be processed. However, a smaller number will cause
# the server to use more of your system's resources.
smtpdelivery.interval=5
This meets my needs.

Resources