mail -s "test mail" < messagebody.txt
Dec 16 06:45:23 Ambidextrous postfix/pickup[16021]: D493648123F: uid=1000 from=<praveen@Ambidextrous>
Dec 16 06:45:23 Ambidextrous postfix/cleanup[18325]: D493648123F: message-id=<20191216011523.D493648123F@Ambidextrous>
Dec 16 06:45:23 Ambidextrous postfix/qmgr[16022]: D493648123F: from=<praveen@Ambidextrous>, size=467, nrcpt=1 (queue active)
Dec 16 06:45:24 Ambidextrous postfix/smtp[18327]: connect to smtp.gmail.com[2404:6800:4003:c03::6d]:587: Network is unreachable
Dec 16 06:45:25 Ambidextrous postfix/smtp[18327]: D493648123F: to=<>, relay=smtp.gmail.com[74.125.24.108]:587, delay=1.6, delays=0.1/0.03/1.3/0.2, dsn=5.7.0, status=bounced (host smtp.gmail.com[74.125.24.108] said: 530-5.7.0 Authentication Required. Learn more at 530 5.7.0 f81sm20379329pfa.118 - gsmtp (in reply to MAIL FROM command))
Dec 16 06:45:25 Ambidextrous postfix/cleanup[18325]: A19DA481245: message-id=<20191216011525.A19DA481245@Ambidextrous>
Dec 16 06:45:25 Ambidextrous postfix/bounce[18328]: D493648123F: sender non-delivery notification: A19DA481245
Dec 16 06:45:25 Ambidextrous postfix/qmgr[16022]: A19DA481245: from=<>, size=2688, nrcpt=1 (queue active)
Dec 16 06:45:25 Ambidextrous postfix/qmgr[16022]: D493648123F: removed
Dec 16 06:45:25 Ambidextrous postfix/local[18329]: A19DA481245: to=<praveen@Ambidextrous>, relay=local, delay=0.08, delays=0.05/0.01/0/0.02, dsn=2.0.0, status=sent (delivered to mailbox)
Dec 16 06:45:25 Ambidextrous postfix/qmgr[16022]: A19DA481245: removed 10 1 Answer
Simply specify a valid FROM email adress, or GMail will not accept to send.
Find some examples here:
echo "This is the message body" | mail -s "Subject: Test Mail" -aFrom:aN\<\> FYI, if you want to send email from scripts or command line with all advanced features, a good workaround could be to use the phpMailer library : attachments, html & text format, DKIM, SPF...
You may also review your PostFix configuration
/etc/postfix/sasl_passwd must contain your GMail account informations on a line looking like this:[smtp.gmail.com]:587 :password/etc/postfix/main.cf must refer to the previous file with smtp_sasl_password_maps
Then use postmap to complie the sasl passwd file