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

前端 未结 4 602
别那么骄傲
别那么骄傲 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:35

    Before using mail.send() I would recommend to test if mail is correctly set :

    if form.process().accepted:
        session.name = form.vars.name
        session.email = form.vars.email
        session.subject = form.vars.subject
        session.message = form.vars.message
        if mail:
            if mail.send(to=['otheremail@yahoo.com'],
                subject='project minerva',
                message= "Hello this is an email send from minerva.com from contact us form.\nName:"+ session.name+" \nEmail : " + session.email +"\nSubject : "+session.subject +"\nMessage : "+session.message+ ".\n "
            ):
                response.flash = 'email sent sucessfully.'
            else:
                response.flash = 'fail to send email sorry!'
        else:
            response.flash = 'Unable to send the email : email parameters not defined'
    elif form.errors:
            response.flash='form has errors.'
    

    Then try to change :

    mail.settings.server = 'smtp@gmail.com:465'
    

    in

    mail.settings.server = 'smtp.gmail.com:465'
    

    or

    mail.settings.server = 'smtp.gmail.com:587'
    

提交回复
热议问题