title: Sending message with attachment in email BytesIO doesn't work - No errors shown - Python/Smtp/Email
body: <p>I am trying to add attachment to the object created below and stored as email. It's all done within a class and this is how the class is initialised:</p>
  <pre><code>class &lt;name&gt;:
      def __init__(self, **kwargs):
          self.msg = kwargs.get(&quot;msg&quot;, MIMEMultipart())
          self.subject = kwargs.get(&quot;subject&quot;, None)
          self.body = kwargs.get(&quot;body&quot;, None)
          self.attachment = kwargs.get(&quot;attachment&quot;, None)
  </code></pre>
  <p><strong>Attachment is not being sent</strong></p>
  <p>The attachments works fine as long as the attachment is of the type <code>str</code>. Add other functionalities of adding body, subject, etc. works fine.
  When I pass a <code>BytesIO()</code> type object, the mail gets sent without any errors or warnings, but the attachment is not being sent.</p>
  <pre><code>for i ,attachment in enumerate(self.attachment,start=1):
              p = MIMEBase('application', 'octet-stream')
              if isinstance(attachment, str):
                  p.set_payload(open(attachment,&quot;rb&quot;).read())
              else:
                  p.set_payload((attachment).read())
              encoders.encode_base64(p)
              p.add_header('Content-Disposition', &quot;attachment&quot;, filename= f'attachment{i}.jpg')
              self.msg.attach(p)
  </code></pre>
  <p><strong>Why am I using <em>BytesIO()</em> in the first place?</strong></p>
  <p>Well, I am trying to send a QR Image, which is saved using</p>
  <pre><code>qr_img.save(BytesIO(),format=&quot;png&quot;)
  </code></pre>
  <p>I am trying to send the image generated from <code>qrcode</code> module without saving it locally.</p>
  <p><strong>Message is sent like this:</strong></p>
  <pre><code>self.server.send_message(msg)
  </code></pre>
  <p>Where <code>self.server</code> is the <code>smtplib.SMTP_SSL()</code> object.</p>
  <p>Any help is appreciated, thanks!</p>