php - site on server A, want to send its email from server B -
i have rather messy situation can't seem think of way resolve.
1 - maintaining live site on shared host, hosting company has limit of 250 emails/hour (or 250 smtp relays per hour). site dating site generates lot of email, limit being reached pretty regularly.
2 - have vps can sent unlimited emails.
i want use 2 send emails 1. obvious answer move site server 2, not option currently.
both setups php/mysql.
thanks in advance.
security considerations
host 2should have ssl(because have vps , maybe enabled) . otherwise other user shared hosting sniff packets because sent in plain text if host2. should keep close @ mail logs.
solution a
when want sent email
1 2make asynchronous request(if needed)1 2. when request asynchronously users not have wait email sent. example use snippet achieve that. url2should url that's hard guess sort of security measurement(basic). example https://www.myvps.com/gfgfdgfdgfcascxzsdadf3rfdfvs3fd (just random string).from
url 2just post fields , sent e-mail. guess pretty simple solution implement.
advantages:
- simple implement
disadvantages:
- could have scaling issues. each time
url 2gets called new process going spawned , there no way throttle sending e-mails. don't think use case hit wall. - if
host 2not have ssl system unsafe.
solution b:
you use google app engine(gae) sending emails. first 1000 mails free , after cost $0.0001 per recipients emailed.
advantages:
- easy implement(python pretty nifty language). there no need asynchronous request because gae's mail asynchronous.
- gae has ssl support connection
server 1can not sniffed. - it scales because on gae.
disadvantage:
- sending email cost money. maybe drop vps , go gae instead(save money?).
solution c:
this solution requires install node.js enviroment(but because on vps should not problem). node.js requires python(>=2.4) install node.js.
advantages:
- insanely fast. don't think need throttling.
- easy implement(node.js/javascript nice). again no need asynchronous request because node.js asynchronous.
- scales(easily) because can throttling no effort.
disadvantages:
- has dependencies(node.js). , node packages(express, connect, node-email)
- could unsafe if not having ssl.
code
i wrote email service in node in couple of minutes.
const port = 4000; const host = 'localhost'; const lib = require('email'); lib.from = ''; // #should set e-mail want sent from. const email = lib.email; const express = require('express'); var app = module.exports = express.createserver( express.bodydecoder() ); app.post('/secret', function(req, res, params) { var = req.body.to; var subject = req.body.subject; var body = req.body.body; if (!(to && subject && body)) { return res.send('param missing'); } res.send('+ok'); var mail = new email({ to: to, subject: subject, body: body }); mail.send(function(err){ if (err) console.log(err); }); }); if (!module.parent) { app.listen(port, host); console.log("express server listening on port %d", app.address().port) }
Comments
Post a Comment