dtd793353
2015-08-27 10:06
浏览 86
已采纳

通过谷歌的SMTP服务器发送电子邮件的最快方式?

im developing a website which sends alot of emails (registration, forgot password, transaction, etc..) and currently i'm using PHPMailer and gmail's SMTP to send them. They work pretty good and i never had a lost email.

So what is wrong?

Well, since it has to login to the SMTP and such it takes longer to load the page. For example when a user makes a transaction it takes about 900-1000ms longer to finish the request. I balieve that sending emails like this is a very bad idea.

What to do?

I never had to send mails this way so i dont know which is the fastest practise.

I was thinking to write a little python or php cli service which has a queue with emails to send. When an email must get delivered it will take care of it.

Not sure if this is perfect. An suggestions?

图片转代码服务由CSDN问答提供 功能建议

即时开发一个发送大量电子邮件的网站(注册,忘记密码,交易等),目前我 使用PHPMailer和gmail的SMTP发送它们。 他们工作得很好,我从来没有丢失过的电子邮件。

那有什么问题?

好吧,因为它必须登录到SMTP并且 这样加载页面需要更长的时间。 例如,当用户进行交易时,完成请求需要大约900-1000ms。 我很高兴发送这样的电子邮件是一个非常糟糕的主意。

怎么办?

我从来没有这样发过邮件所以我不这样做 知道哪个是最快的练习。

我在想写一个小的python或php cli服务,它有一个带有电子邮件发送的队列。 当电子邮件必须交付时,它将负责处理。

不确定这是否完美。 一个建议?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doumanshan6314 2015-08-27 11:12
    已采纳

    I believe that sending emails like this is a very bad idea.

    You are correct.

    Any suggestions?

    Sending mails (or any process that takes a bit of time for that matter) should always be done in the background, so the frontend stays fast.

    You have different ways of doing that:

    • Insert/flag some row in the database, and have a cron job regularly check if there are such rows to be processed. This is simple enough to implement and works well if delay is not a problem. If you need to run the cron too frequently though, then move on to the next solution.
    • Using a third-party queue/messaging service like RabbitMQ. This is a bit longer to setup, but it's a very solid and versatile architecture: the frontend sends whatever tasks you want to the service, which takes care of queuing and distributing them to your workers scripts. Can be used for sending your emails, resizing images, generating PDF, etc. Whatever takes time can be moved in the background.

    Now there is another solution that works for emails in particular, if you have some system administration skills: use a SMTP relay.

    • Instead of querying Gmail SMTP directly (which is slow), your frontend delivers the mails locally (which is fast), and your local mail server (Postfix for example) will take care of forwarding them to Gmail's SMTP.
    点赞 打赏 评论

相关推荐 更多相似问题