title: My code wont fully run through my dictionary and i cant figure out why
body: <p>I am new to coding and have been trying to write an automated email formater and sender but am running into trouble trying to get it to realise when it has already sent someone an email.</p>
  
  <p>I tried using a searchable dictionary as shown in the code below however once it sends one email it stops due to something in the code.</p>
  
  <p>This is only a segment of a class for the full code please ask.</p>
  
  <pre><code>def send_email(self):
      self.message_format()
      if len(self.messages) &gt; 0:
          for i in self.messages:
              user_email = self.messages[i]["email"]
              user_msg = self.messages[i]["message"]
              if i in self.sent_to_list:
                  return False
              else:
                  try:
                      email_conn = smtplib.SMTP(host,port)
                      email_conn.ehlo()
                      email_conn.starttls()
                      email_conn.login(username, password)
                      the_msg = MIMEMultipart("alternative")
                      the_msg["Subject"] = "Hello there!"
                      the_msg["From"] = from_email
                      the_msg["To"] = user_email
                      right_msg = MIMEText(user_msg, "plain")
                      the_msg.attach(right_msg)
                      email_conn.sendmail(from_email, [user_email], the_msg.as_string())
                      email_conn.quit()
                      self.sent_to_list[str(i)] = self.messages[i]
                  except smtplib.SMTPException:
                      print("Error sending message")
                  except smtplib.SMTPAuthenticationError:
                      print("An error occured during login")
              return True
      return False
  </code></pre>