How to add a subject to an email being sent with gmail?
<p>I am trying to send an email using GMAIL with a subject and a message. I have succeeded in sending an email using GMAIL without the implementation of <code>subject</code> and have also been able to receieve the email. However whenever I try to add a subject the program simply does not work.</p>

<pre><code>import smtplib
fromx = 'email@gmail.com'
to  = 'email1@gmail.com'
subject = 'subject' #Line that causes trouble
msg = 'example'
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.ehlo()
server.login('email@gmail.com', 'password')
server.sendmail(fromx, to, subject , msg) #'subject'Causes trouble
server.quit()
</code></pre>

<p>error line:</p>

<pre><code>server.sendmail(fromx, to, subject , msg) #'subject'Causes trouble
</code></pre>

<p>Or just use a package like <a href="https://github.com/kootenpv/yagmail" rel="nofollow">yagmail</a>. Disclaimer: I'm the maintainer.</p>

<pre><code>import yagmail
yag = yagmail.SMTP("email.gmail.com", "password")
yag.send("email1.gmail.com", "subject", "contents")
</code></pre>

<p>Install with <code>pip install yagmail</code></p>

python python-2.7 email gmail subject