So while finalizing the apk-generator for my GSoC project, I faced a roadblock in sending the generated App to the organizer.
Normally the build takes around 10–12 minutes, so asking the user to wait for that long on the website and then providing him/her with a download link did not feel like a good option. (amirite?)
So I and Manan Wason thought of a different approach to this problem, which was to email the generated app to the organzier.
For doing this, we used 2 handy tools MSMTP and Mutt.
We can use MSMTP to send email but unfortunately we cannot include attachments, so we used Mutt to help us send email with attachments from the command line.
So hang tight and follow the rest of the guide to start sending emails from your terminal and get yourself some developer #swag
Step 1 : Installation
Use the following commands to install MSMTP and Mutt
sudo apt-get -y install msmtp
sudo apt-get -y install ca-certificates
sudo apt-get -y install mutt
Step 2 : Configuring MSMTP
Now we’ll MSMTP configuration on /etc/msmtprc with the content below. NOTE : You will have to enter your username and password on this file so make sure to make this file private.
Lets first open this file
Next, add following text to the file,
host smtp.mail.yahoo.com (change this to smtp.gmail.com for gmail)
NOTE : Refrain from using gmail as they might terminate your account for sending email via MSMTP.
For configuring mutt, we’ll use a similar command to edit the file located at /root/.muttrc
Add following text to it which specifies the MSMTP account to use for sending email
set realname=”MY Real Name”
Now lets get ready for the fun part, SENDING THOSE EMAILS 😀
Step 3 : Sending
Now, there are 2 cases that might arise while sending the email,
1 : Sending without attachment
This is pretty straightforward and can be done with either MSMTP or Mutt.
printf “To: email@example.comFrom: firstname.lastname@example.orgSubject: Testing MSMTPnnHello there. This is email test from MSMTP.” | msmtp email@example.com
Entering the following code will send the email to the recipient and also display the sent email in the terminal.
mutt -s “Testing Mutt” — firstname.lastname@example.org < /path/to/body.txt
NOTE : ‘body.txt’ is the file whose contents will be used in the body of the email that will be sent to ‘email@example.com’.
2 : Sending WITH an attachment
Unlike the previous case, this can be done ONLY using Mutt and the code used is
mutt -a /path/to/attachment.txt -s “Testing Mutt — firstname.lastname@example.org < /path/to/body.txt
The syntax is similar to the above case where we sent the email without attachments.
So well, that it then!
If you followed the instructions carefully, you will have a working email client built into your terminal!
Pretty cool right?
So that’s it for this week, hope to catch you next week with some more interesting tips and tutorials.