Sending Email via Console With Custom From Address on Mac Using Gmail

If you want to send an email via the console on your Mac using a custom “From” address with Gmail, you can use the sendmail command. Gmail’s SMTP servers can be configured to allow sending emails from custom addresses. Here’s how you can send an email from the console with a custom “From” address using sendmail:

Prerequisites

  1. You should have a Gmail account set up.

  2. Make sure you have the sendmail command installed on your Mac. You can install it using Homebrew if you don’t have it already:

    1
    
    brew install sendmail

Sending the Email

Method 1: Using printf and Pipe

This method allows you to set the “From” address and other email details using the printf command and pipe it to sendmail. Replace the placeholders with your own email addresses and content.

1
printf "From: Your Name <[email protected]>\nTo: Recipient Name <[email protected]>\nSubject: Your Subject\n\nEmail body text." | sendmail -t

Replace the following placeholders:

  • Your Name with your name.
  • [email protected] with your Gmail email address.
  • Recipient Name with the recipient’s name.
  • [email protected] with the recipient’s email address.
  • Your Subject with the email subject.
  • Email body text with the content of your email.

Method 2: Using Flags

Alternatively, you can use flags to specify the “From” address and other email details when using sendmail. Replace the placeholders with your own email addresses and content.

1
2
3
4
5
6
sendmail -F "Your Name" -f [email protected] -t <<EOF
To: Recipient Name <[email protected]>
Subject: Your Subject

Email body text.
EOF

Replace the following placeholders:

  • Your Name with your name.
  • [email protected] with your Gmail email address.
  • Recipient Name with the recipient’s name.
  • [email protected] with the recipient’s email address.
  • Your Subject with the email subject.
  • Email body text with the content of your email.

Notes

  • Gmail might require you to allow less secure apps to access your account for this to work.
  • You may need to configure your Gmail account to allow “less secure apps” to access it. Be cautious when using this setting, as it can make your account less secure. An alternative is to generate an “App Password” for this purpose.
  • Make sure to replace all placeholders with your actual information.
  • It’s important to test this with your Gmail account and review Gmail’s security settings to ensure that your account is protected.
0%