git has in-built functionality for sending email. This is useful for sending patches to mailing lists. However, this requires a bit of setup. And I use macOS Monterey on a M1 MBP so I wanted to use my own iCloud email for the same. I wrote this so it may help anyone looking to do the same.
- Fetch an app-specific password for iCloud mail.
This is a security measure to avoid having to use your master password. Just head over to Apple ID manage page and click on "App-Specific Passwords". Press the plus button and give it some label like "SMTP for git mail". The password will appear.
- You can do this easily from the terminal using the following commands:
git config --global sendemail.smtpServer "smtp.mail.me.com" git config --global sendemail.smtpServerPort "587" git config --global sendemail.smtpEncryption "tls" git config --global sendemail.smtpUser "your-email@icloud.com" git config --global sendemail.smtpPass "your-app-specific-password"
Alternatively, you can just open the global git config (usually ~/.gitconfig) and paste in the sendemail block like this:
[sendemail]
smtpServer = smtp.mail.me.com
smtpServerPort = 587
smtpEncryption = tls
smtpUser = your-email@icloud.com
smtpPass = your-app-specific-password
- Send the email
Now you're all set to send emails. To send the last commit's code, just type:
git send-email --to=recipient@icloud.com HEAD~1
You should get a response that looks like:
OK. Log says:
Server: smtp.mail.me.com
MAIL FROM:<your-email@icloud.com>
RCPT TO:<recipient@icloud.com>
RCPT TO:<your-email@icloud.com>
From: Your Name <your-email@icloud.com>
To: recipient@icloud.com
Cc: Your Name <your-email@icloud.com>
Subject: [PATCH] My Latest Commit
Date: Thu, 24 Feb 2022 22:19:16 +0530
Message-Id: <20220224164916.12345-1-your-email@icloud.com>
X-Mailer: git-send-email 2.32.0 (Apple Git-132)
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Result: 250
And walla, that's it! You're all set and the email would have been sent.