i am trying send email using web2py with gmail and using smtp setting i have attached all code

前端 未结 4 658
别那么骄傲
别那么骄傲 2021-01-27 09:04

i am trying to create a form in web2py which sends message to an email account on submission mainly i used SQLFORM.factory to create the form then i used gluon.tools import mai

4条回答
  •  無奈伤痛
    2021-01-27 09:31

    For anyone else experiencing issues discovering their mail setting, here's a brute force approach:

    Also available at this gist.

    Code:

    '''
    Place this in a controller and call it, either by url or directly from code.
    An email(or multiple) with the correct settings will be sent to the 
    test address.
    '''
    def test_mail():
        bases = ['yourdomain.com', 'yourhosting.company.net']
        prefixes = ['smtp.', 'mail.', '']
        ports = [':25' ':465', ':993', ':587', '']
        sender = 'someone@yourdomain.com'
        login = 'someone@yourdomain.com:password'
        send_test_to = 'probably.you@gmail.com'
        count = 0
        mail.settings.tls = True #Here so you can set to False if things fail?
        for base in bases:
            for prefix in prefixes:
                for port in ports:
                    server = '{0}{1}{2}'.format(prefix, base, port)
                      msg = 'server: {0} login: {1}'.format(server, login)
                      # So you can correlate with error codes. Note some servers don't like print!
                      print msg
                      mail.settings.server = server
                      mail.settings.sender = sender
                      mail.settings.login = login
                      mail.send(to=[send_test_to],
                            subject='hello',
                            reply_to='us@example.com',
                            message=msg
                            )
                      count += 1
        return dict(message="tried {0} combinations".format(count))
    

提交回复
热议问题