mail.send() feature in web2py for bounced email/ email address that doesnt exist

孤街醉人 提交于 2019-12-13 04:47:52

问题


So I made a small app that sends emails from web2py, connected to the gmail smtp server. The problem here is that it always gives me a success message! Even when the email-id is invalid. I have tested the bounce back feature of gmail by sending mails from gmail to invalid email ids to which gmail says 'Your message has been sent', but on going to the sent folder gives the mailer daemon with a time lag(this differs for different mailing services). I think the mail.send() feature of web2py is unable to capture that and takes the 'Your message has been sent' as confirmation. How can one capture mails that haven't been sent using web2py?

if mail.send(session.email,subject=session.subject,message= session.message):
            response.flash = 'email sent sucessfully.'
else:
            response.flash = 'fail to send email sorry!'

回答1:


mail.send() is only passing the message to the SMTP server, the response simply states that the server successfully received/accepted the message for further processing. To check this disconnect your computer from the net or intentionally break the mail config and try again - mail.send() should fail since it can't connect to the SMTP server to hand it the message.

The actual message processing (including destination address check) happens later on the SMTP server and other servers on the mail delivery path. Processing failures typically cause error emails to be sent back (bouncing) - this is a different level in the email exchange protocol stack than the one at which mail.send() operates.



来源:https://stackoverflow.com/questions/30399926/mail-send-feature-in-web2py-for-bounced-email-email-address-that-doesnt-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!