title: Sending email with smtplib, no errors but no messages delivered
body: <p>**UPDATE2: In the last bit of code of V2 I swapped <code>smtp.sendmail(email_address, address, msg,)</code> with <code>smtp.sendmail(email_address, phone_book, msg,)</code> Accessing the phone_book directly seems to have solved the issue. Here is the working code for anyone that is looking:</p>
  
  <pre><code>import smtplib
  
  email_address = '' # Your email goes here
  email_password = '' # Your password goes here
  phone_book = [''] # List of receivers
  
  
  def Add_Email():
      client_email = input('Email of receiver? ')
      phone_book.append(client_email)
  
  def Add_Subject_Message_Send():    
      with smtplib.SMTP('smtp.gmail.com', 587) as smtp:
              smtp.ehlo()
              smtp.starttls()
              smtp.ehlo()
  
              smtp.login(email_address, email_password)
  
              subject = input('Enter your subject here: ')
              body = input('Enter your message here: ')
  
              msg = f'Subject: {subject}\n\n{body}'
  
              for i in phone_book:
                  address = i
                  smtp.sendmail(email_address, phone_book, msg,)
  
  
  Add_Email()
  Add_Subject_Message_Send()
  </code></pre>
  
  <p>**</p>
  
  <p>**UPDATE: I swapped the code with the simplest versions without GUI. V1 works when subject and body are defined in code. V2 doesn't work when user defines subject and body. Now V2 has this error message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "c:/Users/Me/Desktop/work/infosend/test4.py", line 33, in &lt;module&gt;
      Add_Subject_Message_Send()
    File "c:/Users/Me/Desktop/work/infosend/test4.py", line 29, in Add_Subject_Message_Send
      smtp.sendmail(email_address, address, msg,)
    File "C:\python\lib\smtplib.py", line 885, in sendmail
      raise SMTPRecipientsRefused(senderrs)
  smtplib.SMTPRecipientsRefused: {'': (555, b'5.5.2 Syntax error. l15sm65056407wrv.39 - gsmtp')}
  </code></pre>
  
  <p>** </p>
  
  <p>I'm sending emails using smtplib. As long as subject and body of the message are defined in the code everything works and email gets delivered. When there is no subject or body defined in the code, no errors shows, but message is not delivered.</p>
  
  <p>I want to create a function that will allow me to write what the subject and message is, rather than defining it in the code. My function seems to work, but no messages are being delivered and no error messages received.</p>
  
  <p>Attaching two versions of my code. </p>
  
  <p>First version works. It has defined subject and body.</p>
  
  <p>Second version doesn't work. Includes functions to define subject and body. No errors received in terminal. </p>
  
  <p>V1</p>
  
  <pre><code>import smtplib
  
  email_address = '' # Enter your email address here
  email_password = '' # Enter your email password here
  
  phone_book = [''] # Here enter the email of receiver
  
  with smtplib.SMTP('smtp.gmail.com', 587) as smtp: # Connects with GMAIL
              smtp.ehlo()
              smtp.starttls()
              smtp.ehlo()
  
              smtp.login(email_address, email_password)
  
              subject = 'test3' # Subject and body defined in code = works
              body = 'test3'
  
              msg = f'Subject: {subject}\n\n{body}'
  
              for i in phone_book:
                  address = i
                  smtp.sendmail(email_address, address, msg,)
  </code></pre>
  
  <p>V2</p>
  
  <pre><code>    import smtplib
  
  email_address = '' # Your email goes here
  email_password = '' # Your password goes here
  phone_book = [''] # List of receivers
  
  
  def Add_Email():
      client_email = input('Email of receiver? ')
      phone_book.append(client_email)
  
  def Add_Subject_Message_Send():    
      with smtplib.SMTP('smtp.gmail.com', 587) as smtp:
              smtp.ehlo()
              smtp.starttls()
              smtp.ehlo()
  
              smtp.login(email_address, email_password)
  
              subject = input('Enter your subject here: ')
              body = input('Enter your message here: ')
  
              msg = f'Subject: {subject}\n\n{body}'
  
              for i in phone_book:
                  address = i
                  smtp.sendmail(email_address, address, msg,)
  
  
  Add_Email()
  Add_Subject_Message_Send()
  </code></pre>