Answers.Body: <p>Just because <a href="http://buildwithcraft.com/classreference/services/EmailService#sendEmailByKey-detail" rel="nofollow">EmailService::sendEmailByKey()</a> requires you to pass in a <a href="http://buildwithcraft.com/classreference/models/UserModel" rel="nofollow">UserModel</a>, doesn’t mean that the model has to represent an actual saved user. You can create one on the spot for them:</p>
  
  <pre class="lang-php prettyprint-override"><code>$user = new UserModel();
  $user-&gt;email = 'sergster@abc.xyz';
  $user-&gt;firstName = 'John'; // optional
  $user-&gt;lastName = 'Doe'; // optional
  
  craft()-&gt;email-&gt;sendEmailByKey($user, 'my_key', $variables);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-02T14:03:16.807Z
Answers.Text: Oh yeah, that totally makes sense, thanks! Do you have any insight on the secnd part of my question, namely which version of the email message (control panel vs. translation file) takes precedence?
Answers.UserDisplayName: John O
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-02T15:04:29.040Z
Answers.Text: @JohnO I just edited your question to remove that second part; can you please post it as a new question? (You can see what you originally typed here: http://craftcms.stackexchange.com/posts/11701/revisions)
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-02T15:51:23.393Z
Answers.Text: Thanks for taking care of editing it out. I re-posted the question here: http://craftcms.stackexchange.com/questions/11728/do-email-messages-use-control-panel-or-translation-file-template-when-sending-by
Answers.UserDisplayName: John O
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-01T22:38:45.483Z
Answers.LastActivityDate: 2015-10-01T22:38:45.483Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>In a custom plugin, I would like to use Craft's ability to register email message keys in order to keep emails consistent, and I would like to be able to send these emails to users as well as non-users. My understanding is that I would need to use the sendEmailByKey method of the EmailService to send emails using registered keys, which is defined like this:</p>
  
  <pre><code>public function sendEmailByKey(UserModel $user, $key, $variables = array())
  </code></pre>
  
  <p>This method only accepts a UserModel for the recipient, so it doesn't look like there's a way to send an email by key to an arbitrary email address. Is there a different way to send these registered emails to non-users?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-01T22:23:34.573Z
Comments.Text: Could you just spin of a `new UserModel()` and assign your non-user email to it before calling `sendEmailByKey`?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-10-02T14:04:12.770Z
Comments.Text: Thanks, @BradBell! That seems like it should work and is the same solution Brandon Kelly suggested.
Comments.UserDisplayName: John O
Tags: <emails><usermodel>
Title: Sending email by key to non-user
ThreadText: # Sending email by key to non-user
  
  (Asked by: username_0 on 2015-10-01)
  
  In a custom plugin, I would like to use Craft's ability to register email message keys in order to keep emails consistent, and I would like to be able to send these emails to users as well as non-users. My understanding is that I would need to use the sendEmailByKey method of the EmailService to send emails using registered keys, which is defined like this:
  
  ```
  public function sendEmailByKey(UserModel $user, $key, $variables = array())
  
  ```
  
  This method only accepts a UserModel for the recipient, so it doesn't look like there's a way to send an email by key to an arbitrary email address. Is there a different way to send these registered emails to non-users?
  
  **Tags:** emails, usermodel
  
  > **Comments:**
  > **username_1**: Could you just spin of a `new UserModel()` and assign your non-user email to it before calling `sendEmailByKey`?  
  > **username_0**: Thanks, @username_1! That seems like it should work and is the same solution username_2 suggested.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-10-01. Score: 4 | Accepted answer
  
  Just because [EmailService::sendEmailByKey()](http://buildwithcraft.com/classreference/services/EmailService#sendEmailByKey-detail) requires you to pass in a [UserModel](http://buildwithcraft.com/classreference/models/UserModel), doesn’t mean that the model has to represent an actual saved user. You can create one on the spot for them:
  
  ```php
  $user = new UserModel();
  $user->email = 'sergster@abc.xyz';
  $user->firstName = 'username_0'; // optional
  $user->lastName = 'Doe'; // optional
  
  craft()->email->sendEmailByKey($user, 'my_key', $variables);
  
  ```
  
  > **Comments:**
  > **username_0**: Oh yeah, that totally makes sense, thanks! Do you have any insight on the secnd part of my question, namely which version of the email message (control panel vs. translation file) takes precedence?  
  > **username_2**: @username_0 I just edited your question to remove that second part; can you please post it as a new question? (You can see what you originally typed here: http://craftcms.stackexchange.com/posts/11701/revisions)  
  > **username_0**: Thanks for taking care of editing it out. I re-posted the question here: http://craftcms.stackexchange.com/questions/11728/do-email-messages-use-control-panel-or-translation-file-template-when-sending-by  
  
  ---
  
  