<p>There's nothing that says you have to go through Craft's <a href="https://craftcms.com/classreference/models/EmailModel" rel="nofollow">EmailModel</a>/<a href="https://craftcms.com/classreference/services/EmailService" rel="nofollow">EmailService</a> for this.</p>

<p>Craft ultimately uses the <a href="https://github.com/PHPMailer/PHPMailer" rel="nofollow">PHPMailer</a> library, so you can instantiate it directly and use whatever settings you need (or use a completely <a href="http://swiftmailer.org/" rel="nofollow">different library</a>).</p>

<p>I assume you don't want to cram everyone into to "To Address", so is the plan to set the "To Address" to yourself and BCC the recipient list?</p>

<p>Depending on the number of emails you need to send, I'd probably just have your plugin read from the file and insert into a database table.  Then you could setup a cron job to hit your plugin's controller action to send out (one at a time) X emails over Y time period and delete those from the table until its empty.</p>

<p>As far as not getting flagged as a SMTP relay, in addition to throttling email rates, there are <a href="https://blog.codinghorror.com/so-youd-like-to-send-some-email-through-code/" rel="nofollow">definitely</a> <a href="https://www.mail-tester.com/" rel="nofollow">other</a> things you can do to reduce your chances.</p>

CC BY-SA 3.0
2016-03-23T17:15:40.377Z
2016-03-23T18:11:14.630Z
2016-03-23T18:11:14.630Z
Brad Bell
<p>As someone who's run a mail server professionally, thought I'd expand on a comment. Brad's answer goes over the technical details of sending with Craft, I suppose this answer is more "philosophical"?</p>

<p>Back many years ago,  I'd send newsletters "manually" (using PHPList, pommo, my own home brewed set-up... <em>shudders</em>, etc), these were only a few hundred to a thousand. I'd deal with the bounce backs, vacation notices, etc.  manually. Fun stuff. </p>

<p>These days, it's gotten a bit more complex. As an aside, if you were doing this on any old server directly to the recipient, then you have to worry about reverse DNS (ptr) and SPF DNS records, probably DKIM if you want to round your bases.</p>

<p>Thankfully we have services that handle much of the BS of making sure your e-mail is actually delivered. </p>

<p>The big questions are really how many emails do you have to send, what are you actually sending, and how big is the attachment? </p>

<p>Stuff I'd worry about:</p>

<ul>
<li><p><strong>Attachments are huge spam flags.</strong> If you're sending the same one to every person, is there a way to put that on the server with a link to what you're sending? Or is the attachment also dynamically generated? If it were me, I'd probably set up the attachment on the server with a link to attachment but I can see where you might have to actually attach something.</p></li>
<li><p><strong>Rate limiting.</strong> If you're using MailGun, I wouldn't worry too much about <a href="https://documentation.mailgun.com/user_manual.html#batch-sending" rel="nofollow">rate limiting</a> since they will be doing the "reputation" management on their end so you won't flood the destination mail servers. </p>

<p>If these are B2B e-mail addresses, it's a bit easier since many run individual Exchange boxes so you won't be bumping up against ISP based e-mail accounts—Google Apps, Zoho, etc. probably being the exceptions.</p></li>
<li><p><strong>Are you sending more of a newsletter or <a href="http://kb.mailchimp.com/mandrill/about-transactional-email" rel="nofollow">"transactional"</a> style e-mail?</strong> The latter is everyone gets something slightly different like an order confirmation, upsell, etc.</p>

<p>If you're using Craft like an e-mail newsletter creator (I can see Matrix being awesome for this), you may be better off interfacing with MailChimp, Aweber, Campaign Monitor, etc.  Use their APIs to feed the e-mail data into that software that way and then send it off.  They are better optimized in a one-to-many situation like and can track deliverability for an e-mail blast versus Amazon SES, Mandrill, etc. are more optimized for one-to-one transactional e-mails. It's a subtle difference but it can mean the world of difference for deliverability. </p></li>
</ul>

CC BY-SA 3.0
2016-03-28T00:06:39.063Z
2016-03-28T00:50:30.517Z
2016-03-28T00:50:30.517Z
RitterKnight
<p>I need to take a file, and email it to a large group of people. Naturally, I'll be using a custom plugin Controller to trigger the email blast.</p>

<p>I'm already aware of <a href="https://craftcms.stackexchange.com/questions/1533/best-way-to-include-attachments-using-emailservice-craft-plugin">this similar thread</a>, but I don't believe it will solve my problem. If I remember correctly, Craft's native email model isn't capable of sending to more than one person at a time. More importantly, <em>I don't want our server to be labeled as a spammer!</em></p>

<p>Would it make sense to run this process through a Task? Each individual email could be sent out as a separate step in the task.</p>

<p><strong>What is the best way to bulk email an attachment?</strong></p>

CC BY-SA 3.0
2016-03-23T05:49:31.340Z
Not sure if it's relevant... The site is using Mailgun SMTP to send emails.
Lindsey D
CC BY-SA 3.0
2016-03-23T16:26:15.310Z
Can't you just setup a CRON that sends 10 emails every 1 minute from a Plugin Controller w/ the attachment?
naboovalley
CC BY-SA 3.0
2016-03-23T16:34:05.993Z
Is that the best way? That's what I'm trying to find out. Sending an email every 6 seconds seems like an improvement, but I'm certainly no email/spam expert.
Lindsey D
CC BY-SA 3.0
2016-03-25T05:24:35.587Z
How many emails? If you're using mailgun, I wouldn't fuss too much about rate limiting since they will be doing it on their end. I'm assuming you're sending via api and not smtp? If you were doing this on any old server directly to the recipient, then yeh you got a huge kill list to get it working (ptr and spf dns records, etc). Mailgun is [300 requests per min](https://documentation.mailgun.com/api-domains.html)
RitterKnight
CC BY-SA 3.0
2016-03-25T05:37:37.880Z
Oops wrong link. If you [batch your emails](https://documentation.mailgun.com/user_manual.html#batch-sending) you can rattle off 1000 per batch.
RitterKnight
CC BY-SA 3.0
2016-03-25T16:41:24.950Z
I actually was just using plain SMTP. Sounds like I'd be better off using their actual API to send the emails?
Lindsey D
CC BY-SA 3.0
2016-03-27T23:21:09.333Z
Maybe. Just perusing there docs, I'd personally want to set parameters via an array vs mail headers but it's probably a wash either way. You might run into less problems with outgoing ports on a VPS, etc but that's just a hunch.
RitterKnight
<emails>
Best way to bulk email an attachment?
# Best way to bulk email an attachment?

(Asked by: username_0 on 2016-03-23)

I need to take a file, and email it to a large group of people. Naturally, I'll be using a custom plugin Controller to trigger the email blast.

I'm already aware of [this similar thread](https://craftcms.stackexchange.com/questions/1533/best-way-to-include-attachments-using-emailservice-craft-plugin), but I don't believe it will solve my problem. If I remember correctly, Craft's native email model isn't capable of sending to more than one person at a time. More importantly, *I don't want our server to be labeled as a spammer!*

Would it make sense to run this process through a Task? Each individual email could be sent out as a separate step in the task.

**What is the best way to bulk email an attachment?**

**Tags:** emails

> **Comments:**
> **username_0**: Not sure if it's relevant... The site is using Mailgun SMTP to send emails.  
> **username_1**: Can't you just setup a CRON that sends 10 emails every 1 minute from a Plugin Controller w/ the attachment?  
> **username_0**: Is that the best way? That's what I'm trying to find out. Sending an email every 6 seconds seems like an improvement, but I'm certainly no email/spam expert.  
> **username_2**: How many emails? If you're using mailgun, I wouldn't fuss too much about rate limiting since they will be doing it on their end. I'm assuming you're sending via api and not smtp? If you were doing this on any old server directly to the recipient, then yeh you got a huge kill list to get it working (ptr and spf dns records, etc). Mailgun is [300 requests per min](https://documentation.mailgun.com/api-domains.html)  
> **username_2**: Oops wrong link. If you [batch your emails](https://documentation.mailgun.com/user_manual.html#batch-sending) you can rattle off 1000 per batch.  
> **username_0**: I actually was just using plain SMTP. Sounds like I'd be better off using their actual API to send the emails?  
> **username_2**: Maybe. Just perusing there docs, I'd personally want to set parameters via an array vs mail headers but it's probably a wash either way. You might run into less problems with outgoing ports on a VPS, etc but that's just a hunch.  

---

## 2 answers

### Answer by username_3 on 2016-03-23. Score: 4

There's nothing that says you have to go through Craft's [EmailModel](https://craftcms.com/classreference/models/EmailModel)/[EmailService](https://craftcms.com/classreference/services/EmailService) for this.

Craft ultimately uses the [PHPMailer](https://github.com/PHPMailer/PHPMailer) library, so you can instantiate it directly and use whatever settings you need (or use a completely [different library](http://swiftmailer.org/)).

I assume you don't want to cram everyone into to "To Address", so is the plan to set the "To Address" to yourself and BCC the recipient list?

Depending on the number of emails you need to send, I'd probably just have your plugin read from the file and insert into a database table. Then you could setup a cron job to hit your plugin's controller action to send out (one at a time) X emails over Y time period and delete those from the table until its empty.

As far as not getting flagged as a SMTP relay, in addition to throttling email rates, there are [definitely](https://blog.codinghorror.com/so-youd-like-to-send-some-email-through-code/) [other](https://www.mail-tester.com/) things you can do to reduce your chances.


---

### Answer by username_2 on 2016-03-28. Score: 4

As someone who's run a mail server professionally, thought I'd expand on a comment. Brad's answer goes over the technical details of sending with Craft, I suppose this answer is more "philosophical"?

Back many years ago, I'd send newsletters "manually" (using PHPList, pommo, my own home brewed set-up... *shudders*, etc), these were only a few hundred to a thousand. I'd deal with the bounce backs, vacation notices, etc. manually. Fun stuff.

These days, it's gotten a bit more complex. As an aside, if you were doing this on any old server directly to the recipient, then you have to worry about reverse DNS (ptr) and SPF DNS records, probably DKIM if you want to round your bases.

Thankfully we have services that handle much of the BS of making sure your e-mail is actually delivered.

The big questions are really how many emails do you have to send, what are you actually sending, and how big is the attachment?

Stuff I'd worry about:

* **Attachments are huge spam flags.** If you're sending the same one to every person, is there a way to put that on the server with a link to what you're sending? Or is the attachment also dynamically generated? If it were me, I'd probably set up the attachment on the server with a link to attachment but I can see where you might have to actually attach something.
* **Rate limiting.** If you're using MailGun, I wouldn't worry too much about [rate limiting](https://documentation.mailgun.com/user_manual.html#batch-sending) since they will be doing the "reputation" management on their end so you won't flood the destination mail servers.

  If these are B2B e-mail addresses, it's a bit easier since many run individual Exchange boxes so you won't be bumping up against ISP based e-mail accounts—Google Apps, Zoho, etc. probably being the exceptions.
* **Are you sending more of a newsletter or ["transactional"](http://kb.mailchimp.com/mandrill/about-transactional-email) style e-mail?** The latter is everyone gets something slightly different like an order confirmation, upsell, etc.

  If you're using Craft like an e-mail newsletter creator (I can see Matrix being awesome for this), you may be better off interfacing with MailChimp, Aweber, Campaign Monitor, etc. Use their APIs to feed the e-mail data into that software that way and then send it off. They are better optimized in a one-to-many situation like and can track deliverability for an e-mail blast versus Amazon SES, Mandrill, etc. are more optimized for one-to-one transactional e-mails. It's a subtle difference but it can mean the world of difference for deliverability.


---

