How to set sender email Id while using Flask Mail
<p>I am using Flak Mail to send email from a website's contact form. Contact form has a <code>sender</code> email id field as well. So when I receive the email at "recipient" email id I want <code>from</code> to be set as <code>sender</code> email Id to have the value entered on the form. Following is the class that handles emails:</p>

<pre><code>from flask_mail import Mail, Message

class SendMail:

    def __init__(self, app):
        app.config['MAIL_SERVER']='smtp.gmail.com'
        app.config['MAIL_PORT'] = 465
        app.config['MAIL_USERNAME'] = 'smtpsetup@gmail.com'
        app.config['MAIL_PASSWORD'] = '&lt;password&gt;'
        app.config['MAIL_USE_TLS'] = False
        app.config['MAIL_USE_SSL'] = True
        self.recipient_email = 'recipient@gmail.com'
        self.app = app
        self.mail = Mail(self.app)

    def compile_mail(self, name, email_id, phone_no, msg):
        message = Message(name+" has a query",
                          sender = email_id,
                          recipients=[self.recipient_email])
        message.html = "&lt;b&gt;Name : &lt;/b&gt;"+name+"&lt;br&gt;&lt;b&gt;Phone No :&lt;/b&gt; "+phone_no+"&lt;br&gt;&lt;b&gt;Message : &lt;/b&gt;"+msg
        return message

    def send_mail(self, name, email_id, phone_no, msg):
        message = self.compile_mail(name, email_id, phone_no, msg)
        with self.app.app_context():
            self.mail.send(message)
</code></pre>

<p><code>send_mail</code> method receives four arguments which are the fields entered on the contact form. The problem is, when I send email like this, the <code>from</code> in the email received is set to the SMTP MAIL_USERNAME <code>smtpsetup@gmail.com</code>, despite the fact that I am setting <code>sender</code> parameter in Message object as <code>email_id</code> received from the contact form. 
Not able to figure out how to set sender to a value i want.  </p>

<p>Have you checked that the <code>email_id</code> you are passing in is what you think it is?</p>

<p><a href="https://github.com/mattupstate/flask-mail/blob/master/flask_mail.py#L275" rel="nofollow">The Flask Mail source code</a> suggests that it will only use the default if the <code>sender</code> you pass in is falsy (e.g. None or an empty string).</p>

python flask smtp flask-mail