How to send multiple emails in MODX in single SMTP session? - email

I have a script that sends multiple emails in a loop. Between every email, I reset modMail:
$modx->mail->reset()
Sending becomes really slow since modMail needs to connect to the SMTP server again. I would like to send all emails in a single SMTP session.
I found that PHPMailer has a method clearAllRecipients but the modMail class does not have it. So the following command does not work:
$modx->mail->clearAllRecipients()
Is it safe to call PHPMailer's method directly with the following command:
$modx->mail->mailer->clearAllRecipients()
I am a little worried that something will get later broken if the PHPMailer changes. Or what would be a better solution?

PHPMailer's API isn't likely to change in any way like that precisely because it would cause BC breaks. Doing what you suggest should work just fine, though remember you'll need to also set SMTPKeepAlive = true to make it do this. See the reference implementation in the PHPMailer mailing list example.
If you think that this is something that other modx users would benefit from, you could add it to the wrapper they provide (and submit a PR for it) so that you can be abstracted away from PHPMailer's internal API, and thus protected from future changes that way.

Related

PHPlist - running it from localhost with tracking via live website

I've got a significantly large mailing list - 50K+ subscribers. To avoid stressing my servers, I would like to avoid sending emails through a components embedded on my website. Sending through here sends the CPU usage through the roof - so I'd like to be able to send emails locally. I can easily send emails through mandrillapp, so sending the emails out is not a problem. However, I've hit a bit of a snag.
Phplist seems to assume it is living on a public site, and inserts tracking info which routes the users to a phplist directory on my site (which obviously) does not exist.
Question 1: First of all, I'd like to avoid embedding this tracking - is this possible? Or else is there someway to include it and avoid the 404 error. Would I have to install phplist anyway on the server?
Question 2: I've already got acymailing to handle unsubscribes, so is it actually possible to keep this in place - just to make sure the acymailing is still my point of reference?
Question 3: How do people handle sending out large mailing lists? I know CampaignMonitor, MailChimp etc, but these get a bit expensive for my situation. I'd like to keep sending "internally" so to speak. Is there an elegant solution which will NOT kill my server but is not too expensive? I know I want to have the cake and eat, but it would be nice to hear what people out there are doing.
TIA
David

How to create RFC822 email message with comment inside message?

I'm uploading messages into my IMAP mail server via IMAP store operation. However, I would like to add "comments" to these messages so that when I download these emails again I know the they are created by "store". Basically, I need to add text which will be ignored by the formal semantics of parsing RFC822.
The specification of http://www.ietf.org/rfc/rfc822.txt defines how to add comments but I cannot make it working :(
Does anybody has en example of a RFC822 message with a comment in it?
You are probably looking for IMAP's annotations. However, it's an extension which is far from being common -- quite a lot of IMAP servers do not support it.
It seems that having a special "flag" on each message you created is something which would be enough for you. If that is correct, then simply using IMAP flags (or keywords) is what you're looking for. Simply add one special flag, like thisIsProducedByFooSoftware to the APPEND operation. (You said you were doing that via STORE -- that's wrong, in IMAP, STORE manipulates just FLAGS, it doesn't add new messages. New messages are added by APPEND.)

PEAR Mail using gmail SMTP won't send 2 emails in sucession

I have PEAR Mail and Mail_mime all working very nicely using gmail's SMTP server to send. Thanks to some posts on here that helped me get that far!
But, in some scenarios, I need to send two emails, with different content, and to different recipients one right after the other. This is refusing to work.
I can confirm both the emails I am trying to send are well-formed and valid, as both will send with the other one commented out. But whenever I attempt to send them both, only the first gets through. I have tried putting php to sleep for 10 seconds in between, and I have tried sending the second email in a different script that gets called after the end of the first. Nothing.
I realise this is a pretty obscure problem as I found no other articles mentioning this. I haven't included any code because, as stated, I know the code works fine.
So I am hoping in vein that someone might have a bright idea as to why this might be.
Thanks in advance.
SOLVED: changing
include('Mail.php');
to
require_once('Mail.php');
fixed the problem.

Email to rss on server

for my group at the university I'd like to set up a server-sided email-to-rss service.
It should work like that, that different people can send emails to a certain address (nothing proprietary like gmail but a certain imap or pop server) which will the be translated into an rss feed. One main and important feature has to be that one can see the sender of the email in the feed. Furthermore it would be nice (to take the load off the server) if the emails get translated to a feed only once a day or so.
Does anyone has some input on this subject? Are there any scripts/services which will allow that?
Thanks a bunch.
Instead of "reinventing the wheel", you could use a mailing list that supports RSS. Your people can then write the mails to the mailing list and you can then use the mailing list's RSS feed however you intend to.
This should help you find a solution: https://encrypted.google.com/search?q=mailing%20list%20rss
Pick a programming language you're familiar with, then use either an imap library to fetch the E-mails (through cron, every hour or something like that), or if you have access to procmail on your mail server, launch your script as an email arrives (this shouldn't be too much work to handle for a server, unless you're talking a vast amount of E-mail).
The script would just insert the E-mails into a database, before extracting them and outputting the RSS-feed directly from that (this shouldn't be more than a handful of lines of code).
There's a couple of providers that does this for you, although it seems that the most popular ones have disappeared. Advanced Email2RSS seems to be an option, although I have no idea how good they are or if it'll even solve your issue.

Magento Email Templates: Blocks not rendering from adminhtml

I fear I've stumbled into unknown Magento territory. I have exhausted what's left of my Googling abilities and have come up short, so I thought I'd try my luck here.
Our platform is Magento Enterprise 1.9.1.1.
We use an archaic print solution that reads orders via ODBC. As such, we can't have it read from Magento's MySQL database directly (thanks to the high likelihood of change). What I've done is extend Mage_Sales_Model_Order to intercept the _beforeSave() function with direct SQL queries to another database, before returning parent::_beforeSave(). There are likely better ways to have done this, but it's done now, and functional, and regardless it is not where my problem lies.
If any SQL errors are thrown, updates are rolled back and the errors & order data are passed to a function that sends an email to a mailing list with the error information. The email template file in /locale/en_US/template/email/ calls on a .phtml file to process the arrays of data like so:
{{block type='core/template' area='frontend' template='/email/errors/order/beforesave.phtml' orderdata=$orderdata errors=$errors}}
This is functionality I borrowed from /locale/en_US/template/email/sales/shipment_new.phtml. And this is also where I hit my roadblock. The email fires fine from the front end, if errors are encountered when the user is processing an order. If you make order changes from adminhtml, the email is sent, but without the above mentioned block.
I have tried with and without area='frontend' in the block call, and the script exhibits the same behaviour regardless.
I think that the problem may be in my XML, though it finds the template itself just fine from both admin and frontend (and this block is not required to be defined in my XML anywhere). I can also not find any examples of this within Magento's own files, or anywhere on the internet.
Any help would be more than greatly appreciated. This is doing my head in!
Mike
Are you setting the "area" for the actual email template? E.g.:
$emailTemplate = Mage::getModel('core/email_template');
$emailTemplate
->setDesignConfig(array('area' => 'frontend', 'store' => $storeId));
Possible duplicate of sharing template between frontend and backend (admin or adminhtml) in magento.
Don't mean to revive a dead question; just tying up the loose end.
#ColinM: My thoughts were the same as yours, but that somehow didn't work for me. Maybe I don't understand the purpose of setDesignConfig(). Anyhow, the link above worked perfectly for me, in the same scenario as that of the original poster.