How to send email via SMTP in Linux script?

Hello All Expert-Exchange,

Now I have a Linux posfix/dovecot mail server and I set up a script to send daily report via email with sendmail but after a few week it fail in to spam:
pflogsumm /var/log/maillog | formail -c -I"Subject: Mail Daily Report" -I"From: Example Mail <root@crosswired.net>" -I"To: me@example.com" -I"Received: from Postmaster" | sendmail postmaster@example.com

Open in new window



and now I want this script to send mail via SMTP but I cannot find how.
Can you give any suggestion?
LVL 1
Sida SayInfrastructure EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hello WorldCommented:
Hi,

You can use Send-MailMessage script in powershell to send message.
In addition, I find a useful function script to send message, for your reference:
https://gallery.technet.microsoft.com/scriptcenter/Simple-Powershell-function-8e826d7c
Note: this command is used for Windows OS, instead for Linux.
0
TobiasHolmCommented:
This sends a SMTP mail in Linux from command line or in a Linux bash-script:
mail -s "subject here" email@address.com <<< "message"

Open in new window


If your mail are classified as spam, the reason is not the sending command, but the receiving end of your mail delivery chain. Check your spam settings.
0
Jan SpringerCommented:
this is what i use:


#!/bin/bash

report="/path/to/file"

cat $report | mailx -s "Put your subject here" you@domain.com
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Email Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.