Why text attachment sent using Flask Mail is empty?
<p>I am attempting to send an email with Flask-Mail with a .txt file attachment. Thus far either I get an error or the email sends but the .txt. file is blank I've tried it two ways:</p>

<p>One way following the documentation:</p>

<pre><code>with current_app.open_resource("sample.txt") as fp:
    msg.attach("sample.txt","text/plain", fp.read())
</code></pre>

<p>This leads to an Error: </p>

<pre><code>TypeError: 'exceptions.IOError' object is not callable
</code></pre>

<p>I also tried it without the open_resource method:</p>

<pre><code> msg.attach("sample.txt","text/plain")
    mail.send(msg)
</code></pre>

<p>This led to the email sending but the .txt. attachment was blank.</p>

<p>Full try/except block below</p>

<pre><code>try: 
    msg = Message("New File",
              sender="SENDER",
              recipients=["RECIPIENT"])
    msg.body = "Hello Flask message sent from Flask-Mail"
    with current_app.open_resource("sample.txt") as fp:
        msg.attach("sample.txt","text/plain", fp.read())
    mail.send(msg)
except Exception as e:
    return e
return "file was successfully sent"
</code></pre>

<p>What am I missing in order for the attachment to be properly sent?</p>