def send_welcome_message(self, user, base_url):
        """ Send welcome mail with email confirmation link """
        if not self.require_confirmation and not self.welcome_message:
            return

        # get subject
        subject = ''
        subjects = self.email_subjects
        if self.require_confirmation:
            subject = 'Welcome, please activate your account!'
            if 'welcome_confirm' in subjects.keys():
                subject = subjects['welcome_confirm']
        if not self.require_confirmation:
            subject = 'Welcome to our site!'
            if 'welcome' in subjects.keys():
                subject = subjects['welcome']

        # prepare data
        sender = current_app.config['MAIL_DEFAULT_SENDER']
        recipient = user.email
        link = '{url}/{link}/'.format(
            url=base_url.rstrip('/'),
            link=user.email_link
        )
        data = dict(link=link)

        # render message
        if self.require_confirmation:
            html = render_template('user/mail/account-confirm.html', **data)
            txt = render_template('user/mail/account-confirm.txt', **data)
        else:
            html = render_template('user/mail/welcome.html', **data)
            txt = render_template('user/mail/welcome.txt', **data)

        # and send
        mail.send(Message(
            subject=subject,
            recipients=[recipient],
            body=txt,
            html=html,
            sender=sender
        ))
def send_welcome_message ( self , user , base_url ) : if not self . require_confirmation and not self . welcome_message : return subject = '' subjects = self . email_subjects if self . require_confirmation : subject = 'Welcome, please activate your account!' if 'welcome_confirm' in subjects . keys ( ) : subject = subjects [ 'welcome_confirm' ] if not self . require_confirmation : subject = 'Welcome to our site!' if 'welcome' in subjects . keys ( ) : subject = subjects [ 'welcome' ] sender = current_app . config [ 'MAIL_DEFAULT_SENDER' ] recipient = user . email link = '{url}/{link}/' . format ( url = base_url . rstrip ( '/' ) , link = user . email_link ) data = dict ( link = link ) if self . require_confirmation : html = render_template ( 'user/mail/account-confirm.html' , ** data ) txt = render_template ( 'user/mail/account-confirm.txt' , ** data ) else : html = render_template ( 'user/mail/welcome.html' , ** data ) txt = render_template ( 'user/mail/welcome.txt' , ** data ) mail . send ( Message ( subject = subject , recipients = [ recipient ] , body = txt , html = html , sender = sender ) )
Send welcome mail with email confirmation link