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 <>" -I"To:" -I"Received: from Postmaster" | sendmail

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?
Sida SayInfrastructure EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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:

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:
Note: this command is used for Windows OS, instead for Linux.
This sends a SMTP mail in Linux from command line or in a Linux bash-script:
mail -s "subject here" <<< "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.
Jan SpringerCommented:
this is what i use:



cat $report | mailx -s "Put your subject here"

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.