title: Error: While sending the mail via smtplib in sendmail() function
body: <pre><code>from asyncio import constants
  import pandas as pd
  import smtplib as smt
  from email.mime.multipart import MIMEMultipart
  from email.mime.text import MIMEText
  from getpass import getpass
  
  print(&quot;Reading mails from Excel&quot;)
  data = pd.read_excel(&quot;info.xlsx&quot;)
  emailData = data.get(&quot;Email&quot;)
  emailList = list(emailData)
  
  try:
      # SMTP Object
      print(&quot;In process...&quot;)
      mailServer = smt.SMTP(&quot;smtp.gmail.com&quot;, 587)
      mailServer.starttls()
      # Inputting email and password
      senderMail = input(&quot;Enter your Email address: &quot;)
      senderPass = getpass(&quot;Input your password: &quot;)
      # Setting up the email subject, to, from, and message
      fromEmail = senderMail
      toEmail = emailList
      Emailmessage = MIMEMultipart(&quot;alternative&quot;)
      Emailmessage['Subject'] = &quot;Testing for Python Project&quot;
      Emailmessage['from'] = senderMail
  
      # Creating the text via HTML
      messageHTML = '''
      &lt;html&gt;
          &lt;head&gt;
              &lt;style&gt;
                  .btn{
                    background:red;
                  }
              &lt;/style&gt;
          &lt;/head&gt;
          &lt;body&gt;
              &lt;h1&gt;HEading 1&lt;/h1&gt;
              &lt;button id=&quot;btn&quot;&gt;Test&lt;/button&gt;
          &lt;/body&gt;
      &lt;/html&gt;
      '''
  
      # login via email
      mailServer.login(senderMail, senderPass)
      print(&quot;Login Successful&quot;)
  
      # Attach the message and Multipart
      textMsg = MIMEText(messageHTML, &quot;html&quot;)
      Emailmessage.attach(textMsg)
  
      # Sending the email
      mailServer.sendmail(fromEmail, toEmail, Emailmessage.as_string())
  
      for email in emailList:
          print(&quot;Message has been sent to &quot;, emailList[email])
  
      mailServer.quit()
  
  
  except Exception as error:
      print(error)
  </code></pre>
  <p>When I run this code, I get an error while sending the mail. My login is successful also it's successfully fetched the data from xlsx file but I don't know why this error occurred. I think while sending the mail mailserver.sendmail(fromEmail, toEmail, Emailmessage.as_string()) here third argument i.e, Emailmessage.as_string() is throwing error, Still not sure</p>
  <p>It's raising an exception as:</p>
  <p>list indices must be integers or slices, not str</p>
  <p>Please help me to solve this problem.</p>