本文整理汇总了PHP中EmailBox::resolveAndGetByName方法的典型用法代码示例。如果您正苦于以下问题:PHP EmailBox::resolveAndGetByName方法的具体用法?PHP EmailBox::resolveAndGetByName怎么用?PHP EmailBox::resolveAndGetByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EmailBox
的用法示例。
在下文中一共展示了EmailBox::resolveAndGetByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
SecurityTestHelper::createSuperAdmin();
self::$emailHelperSendEmailThroughTransport = Yii::app()->emailHelper->sendEmailThroughTransport;
static::$userpsg = UserTestHelper::createBasicUser('userpsg');
static::$usercstmsmtp = UserTestHelper::createBasicUser('usercstmsmtp');
static::$basicuser = UserTestHelper::createBasicUser('basicuser');
static::$bothSGandCstmUser = UserTestHelper::createBasicUser('bothSGandCstmUser');
$someoneSuper = UserTestHelper::createBasicUser('someoneSuper');
$group = Group::getByName('Super Administrators');
$group->users->add($someoneSuper);
$saved = $group->save();
assert($saved);
// Not Coding Standard
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
if (EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) {
EmailMessageTestHelper::createEmailAccountForMailerFactory(static::$usercstmsmtp);
EmailMessageTestHelper::createEmailAccountForMailerFactory(static::$bothSGandCstmUser);
}
SendGrid::register_autoloader();
Smtpapi::register_autoloader();
if (SendGridTestHelper::isSetSendGridAccountTestConfiguration()) {
SendGridTestHelper::createSendGridEmailAccount(static::$userpsg);
SendGridTestHelper::createSendGridEmailAccount(static::$bothSGandCstmUser);
Yii::app()->sendGridEmailHelper->apiUsername = Yii::app()->params['emailTestAccounts']['sendGridGlobalSettings']['apiUsername'];
Yii::app()->sendGridEmailHelper->apiPassword = Yii::app()->params['emailTestAccounts']['sendGridGlobalSettings']['apiPassword'];
Yii::app()->sendGridEmailHelper->setApiSettings();
Yii::app()->sendGridEmailHelper->init();
}
// Delete item from jobQueue, that is created when new user is created
Yii::app()->jobQueue->deleteAll();
}
示例2: testRenderSummaryContentWithEmailMessage
/**
* Testing that each model type can render properly and does not throw an exception
*/
public function testRenderSummaryContentWithEmailMessage()
{
$super = User::getByUsername('super');
$billy = User::getByUsername('billy');
$this->assertEquals(0, EmailMessage::getCount());
$emailMessage = new EmailMessage();
$emailMessage->owner = BaseControlUserConfigUtil::getUserToRunAs();
$emailMessage->subject = 'My First Email';
//Set sender, and recipient, and content
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'My First Message';
$emailContent->htmlContent = 'Some fake HTML content';
$emailMessage->content = $emailContent;
//Sending from the system, does not have a 'person'.
$sender = new EmailMessageSender();
$sender->fromAddress = 'system@somewhere.com';
$sender->fromName = 'Zurmo System';
$sender->personsOrAccounts->add($super);
$emailMessage->sender = $sender;
//Recipient is billy.
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'billy@fakeemail.com';
$recipient->toName = 'Billy James';
$recipient->type = EmailMessageRecipient::TYPE_TO;
$recipient->personsOrAccounts->add($billy);
$emailMessage->recipients->add($recipient);
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
$saved = $emailMessage->save();
$this->assertTrue($saved);
$content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'HomeModule');
$content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER, 'HomeModule');
$content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'UserModule');
$content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER, 'UserModule');
}
示例3: createDraftSendGridSystemEmail
public static function createDraftSendGridSystemEmail($subject, User $owner)
{
$emailMessage = new EmailMessage();
$emailMessage->owner = $owner;
$emailMessage->subject = $subject;
//Set sender, and recipient, and content
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'My First Message';
$emailContent->htmlContent = 'Some fake HTML content';
$emailMessage->content = $emailContent;
//Sending from the system, does not have a 'person'.
$sender = new EmailMessageSender();
$sender->fromAddress = 'system@somewhere.com';
$sender->fromName = 'Zurmo System';
$emailMessage->sender = $sender;
//Recipient is billy.
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'billy@fakeemail.com';
$recipient->toName = 'Billy James';
$recipient->type = EmailMessageRecipient::TYPE_TO;
$emailMessage->recipients->add($recipient);
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
//Save, at this point the email should be in the draft folder
$saved = $emailMessage->save();
if (!$saved) {
throw new NotSupportedException();
}
return $emailMessage;
}
示例4: resolveEmailMessageFromPostData
/**
* Given post data and an email message, populate the sender and account on the email message if possible.
* Also add message recipients and any attachments.
* @param array $postData
* @param EmailMessage $emailMessage
* @param User $userToSendMessagesFrom
* @return boolean
*/
public static function resolveEmailMessageFromPostData(array &$postData, CreateEmailMessageForm $emailMessageForm, User $userToSendMessagesFrom)
{
$postVariableName = get_class($emailMessageForm);
Yii::app()->emailHelper->loadOutboundSettingsFromUserEmailAccount($userToSendMessagesFrom);
$toRecipients = explode(",", $postData[$postVariableName]['recipientsData']['to']);
// Not Coding Standard
static::attachRecipientsToMessage($toRecipients, $emailMessageForm->getModel(), EmailMessageRecipient::TYPE_TO);
if (ArrayUtil::getArrayValue($postData[$postVariableName]['recipientsData'], 'cc') != null) {
$ccRecipients = explode(",", $postData[$postVariableName]['recipientsData']['cc']);
// Not Coding Standard
static::attachRecipientsToMessage($ccRecipients, $emailMessageForm->getModel(), EmailMessageRecipient::TYPE_CC);
}
if (ArrayUtil::getArrayValue($postData[$postVariableName]['recipientsData'], 'bcc') != null) {
$bccRecipients = explode(",", $postData[$postVariableName]['recipientsData']['bcc']);
// Not Coding Standard
static::attachRecipientsToMessage($bccRecipients, $emailMessageForm->getModel(), EmailMessageRecipient::TYPE_BCC);
}
if (isset($postData['filesIds'])) {
static::attachFilesToMessage($postData['filesIds'], $emailMessageForm->getModel());
}
$emailAccount = EmailAccount::getByUserAndName($userToSendMessagesFrom);
$sender = new EmailMessageSender();
$sender->fromName = Yii::app()->emailHelper->fromName;
$sender->fromAddress = Yii::app()->emailHelper->fromAddress;
$sender->personOrAccount = $userToSendMessagesFrom;
$emailMessageForm->sender = $sender;
$emailMessageForm->account = $emailAccount;
$emailMessageForm->content->textContent = EmailMessageUtil::resolveTextContent(ArrayUtil::getArrayValue($postData[$postVariableName]['content'], 'htmlContent'), null);
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessageForm->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_OUTBOX);
return $emailMessageForm;
}
示例5: testRun
public function testRun()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$outboxFolder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_OUTBOX);
$sentFolder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
$emailMessage = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
$emailMessage->folder = $outboxFolder;
$saved = $emailMessage->save();
$this->assertTrue($saved);
$emailMessageId = $emailMessage->id;
$emailMessage->forget();
unset($emailMessage);
$emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
$emailMessage2->folder = $outboxFolder;
$saved = $emailMessage2->save();
$this->assertTrue($saved);
$emailMessage2Id = $emailMessage2->id;
$emailMessage2->forget();
unset($emailMessage2);
$this->assertEquals(2, EmailMessage::getCount());
$job = new ProcessOutboundEmailJob();
$this->assertTrue($job->run());
$emailMessages = EmailMessage::getAll();
$this->assertEquals(2, count($emailMessages));
$emailMessage = EmailMessage::getById($emailMessageId);
$this->assertEquals($sentFolder, $emailMessage->folder);
$emailMessage2 = EmailMessage::getById($emailMessage2Id);
$this->assertEquals($sentFolder, $emailMessage2->folder);
}
示例6: setUpBeforeClass
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
SecurityTestHelper::createSuperAdmin();
AllPermissionsOptimizationUtil::rebuild();
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
}
示例7: testRun
public function testRun()
{
$quote = DatabaseCompatibilityUtil::getQuote();
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
//Create 2 sent notifications, and set one with a date over a week ago (8 days ago) for the modifiedDateTime
$emailMessage = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
$emailMessage->folder = $folder;
$saved = $emailMessage->save();
$this->assertTrue($saved);
$modifiedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 8);
$sql = "Update item set modifieddatetime = '" . $modifiedDateTime . "' where id = " . $emailMessage->getClassId('Item');
ZurmoRedBean::exec($sql);
$emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('My Email Message 2', $super);
$emailMessage2->folder = $folder;
$saved = $emailMessage2->save();
$this->assertTrue($saved);
$this->assertEquals(2, EmailMessage::getCount());
$job = new ClearSentNotificationsEmailJob();
$this->assertTrue($job->run());
$emailMessages = EmailMessage::getAll();
$this->assertEquals(1, count($emailMessages));
$this->assertEquals($emailMessage2->id, $emailMessages[0]->id);
}
示例8: testCreateEmailMessageThatIsANotification
/**
* A notification email is different than a regular outbound email because it is owned by a super user
* that is different than the user logged in. So the sender does not have a 'person'
*/
public function testCreateEmailMessageThatIsANotification()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$billy = User::getByUsername('billy');
$this->assertEquals(0, EmailMessage::getCount());
$emailMessage = new EmailMessage();
$emailMessage->owner = BaseControlUserConfigUtil::getUserToRunAs();
$emailMessage->subject = 'My First Email';
//Set sender, and recipient, and content
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'My First Message';
$emailContent->htmlContent = 'Some fake HTML content';
$emailMessage->content = $emailContent;
//Sending from the system, does not have a 'person'.
$sender = new EmailMessageSender();
$sender->fromAddress = 'system@somewhere.com';
$sender->fromName = 'Zurmo System';
$emailMessage->sender = $sender;
//Recipient is billy.
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'billy@fakeemail.com';
$recipient->toName = 'Billy James';
$recipient->type = EmailMessageRecipient::TYPE_TO;
$recipient->personsOrAccounts->add($billy);
$emailMessage->recipients->add($recipient);
//At this point the message is in no folder
$this->assertTrue($emailMessage->folder->id < 0);
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
//Save, at this point the email should be in the draft folder
$saved = $emailMessage->save();
$this->assertTrue($saved);
$this->assertTrue($emailMessage->folder->id > 0);
$this->assertEquals(0, EmailMessageSendError::getCount());
$emailMessageSendError = new EmailMessageSendError();
$data = array();
$data['message'] = 'error message';
$emailMessageSendError->serializedData = serialize($data);
$emailMessage->folder = EmailFolder::getByBoxAndType($emailMessage->folder->emailBox, EmailFolder::TYPE_OUTBOX_ERROR);
$emailMessage->error = $emailMessageSendError;
$saved = $emailMessage->save();
$this->assertTrue($saved);
$this->assertEquals(1, EmailMessageSendError::getCount());
//Now swap the error with a new one
$emailMessageId = $emailMessage->id;
$emailMessage->forget();
$emailMessage = EmailMessage::getById($emailMessageId);
$emailMessageSendError = new EmailMessageSendError();
$data = array();
$data['message'] = 'error message 2';
$emailMessageSendError->serializedData = serialize($data);
$emailMessage->error = $emailMessageSendError;
$saved = $emailMessage->save();
$this->assertTrue($saved);
$this->assertEquals(1, EmailMessageSendError::getCount());
}
示例9: resolveSearchAttributeDataForAllLatestActivities
public function resolveSearchAttributeDataForAllLatestActivities($searchAttributeData)
{
assert('is_array($searchAttributeData)');
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$searchAttributeData = parent::resolveSearchAttributeDataForAllLatestActivities($searchAttributeData);
$clausesCount = count($searchAttributeData['clauses']);
$searchAttributeData['clauses'][$clausesCount + 1] = array('attributeName' => 'folder', 'relatedModelData' => array('attributeName' => 'emailBox', 'operatorType' => 'doesNotEqual', 'value' => $box->id));
if ($searchAttributeData['structure'] != null) {
$searchAttributeData['structure'] .= ' and ';
}
$searchAttributeData['structure'] .= $clausesCount + 1;
return $searchAttributeData;
}
示例10: run
/**
*
* (non-PHPdoc)
* @see BaseJob::run()
*/
public function run()
{
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$oneWeekAgoTimeStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 7);
$searchAttributeData = array();
$searchAttributeData['clauses'] = array(1 => array('attributeName' => 'modifiedDateTime', 'operatorType' => 'lessThan', 'value' => $oneWeekAgoTimeStamp), 2 => array('attributeName' => 'folder', 'relatedAttributeName' => 'type', 'operatorType' => 'equals', 'value' => EmailFolder::TYPE_SENT), 3 => array('attributeName' => 'folder', 'relatedAttributeName' => 'emailBox', 'operatorType' => 'equals', 'value' => $box->id));
$searchAttributeData['structure'] = '1 and 2 and 3';
$joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('EmailMessage');
$where = RedBeanModelDataProvider::makeWhere('EmailMessage', $searchAttributeData, $joinTablesAdapter);
$emailMessageModels = EmailMessage::getSubset($joinTablesAdapter, null, self::$pageSize, $where, null);
foreach ($emailMessageModels as $emailMessage) {
$emailMessage->delete();
}
return true;
}
示例11: process
/**
* @throws MissingRecipientsForEmailMessageException
*/
public function process()
{
$emailTemplate = EmailTemplate::getById((int) $this->emailMessageForm->emailTemplateId);
$emailMessage = new EmailMessage();
$emailMessage->owner = $this->triggeredByUser;
$emailMessage->subject = $this->resolveEmailTemplateSubjectForModelData($emailTemplate);
$emailContent = new EmailMessageContent();
$emailContent->textContent = $this->resolveEmailTemplateTextContentForModelData($emailTemplate);
$emailContent->htmlContent = $this->resolveEmailTemplateHtmlContentForModelData($emailTemplate);
$emailMessage->content = $emailContent;
$emailMessage->sender = $this->resolveSender();
$this->resolveRecipients($emailMessage);
if ($emailMessage->recipients->count() == 0) {
throw new MissingRecipientsForEmailMessageException();
}
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
Yii::app()->emailHelper->send($emailMessage);
}
示例12: testExportRelationAttributes
public function testExportRelationAttributes()
{
$report = new Report();
$report->setType(Report::TYPE_ROWS_AND_COLUMNS);
$report->setModuleClassName('EmailMessagesModule');
$report->setFiltersStructure('');
$emailMessage = new EmailMessage();
$emailMessage->owner = Yii::app()->user->userModel;
$emailMessage->subject = 'A test email';
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'A test text message from Zurmo.';
$emailContent->htmlContent = 'A test text message from Zurmo.';
$emailMessage->content = $emailContent;
$sender = new EmailMessageSender();
$sender->fromAddress = 'super@zurmo.com';
$sender->fromName = 'super';
$sender->personsOrAccounts->add(Yii::app()->user->userModel);
$emailMessage->sender = $sender;
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'billy@joe.com';
$recipient->toName = 'Test Recipient';
$recipient->type = EmailMessageRecipient::TYPE_TO;
$emailMessage->recipients->add($recipient);
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
$this->assertTrue($emailMessage->save());
$displayAttribute1 = new DisplayAttributeForReportForm('EmailMessagesModule', 'EmailMessage', Report::TYPE_ROWS_AND_COLUMNS);
$displayAttribute1->setModelAliasUsingTableAliasName('relatedModel');
$displayAttribute1->attributeIndexOrDerivedType = 'sender___User__personsOrAccounts__Inferred___firstName';
$report->addDisplayAttribute($displayAttribute1);
$displayAttribute2 = new DisplayAttributeForReportForm('EmailMessagesModule', 'EmailMessage', Report::TYPE_ROWS_AND_COLUMNS);
$displayAttribute2->setModelAliasUsingTableAliasName('relatedModel');
$displayAttribute2->attributeIndexOrDerivedType = 'sender___Contact__personsOrAccounts__Inferred___firstName';
$report->addDisplayAttribute($displayAttribute2);
$dataProvider = new RowsAndColumnsReportDataProvider($report);
$adapter = ReportToExportAdapterFactory::createReportToExportAdapter($report, $dataProvider);
$compareHeaderData = array('Sender >> Users >> First Name', 'Sender >> Contacts >> First Name');
$compareRowData = array(array('Clark', ''));
$this->assertEquals($compareHeaderData, $adapter->getHeaderData());
$this->assertEquals($compareRowData, $adapter->getData());
}
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:41,代码来源:EmailMessagesRowsAndColumnsReportToExportAdapterTest.php
示例13: run
/**
*
* (non-PHPdoc)
* @see BaseJob::run()
*/
public function run()
{
$messageContent = null;
$userToSendMessagesFrom = BaseControlUserConfigUtil::getUserToRunAs();
$emailMessage = new EmailMessage();
$emailMessage->owner = Yii::app()->user->userModel;
$emailMessage->subject = Zurmo::t('EmailMessagesModule', 'A test email from Zurmo', LabelUtil::getTranslationParamsForAllModules());
$emailContent = new EmailMessageContent();
$emailContent->textContent = Zurmo::t('EmailMessagesModule', 'A test text message from Zurmo.', LabelUtil::getTranslationParamsForAllModules());
$emailContent->htmlContent = Zurmo::t('EmailMessagesModule', 'A test text message from Zurmo.', LabelUtil::getTranslationParamsForAllModules());
$emailMessage->content = $emailContent;
$sender = new EmailMessageSender();
$sender->fromAddress = Yii::app()->emailHelper->resolveFromAddressByUser($userToSendMessagesFrom);
$sender->fromName = Yii::app()->emailHelper->resolveFromNameForSystemUser($userToSendMessagesFrom);
$emailMessage->sender = $sender;
$recipient = new EmailMessageRecipient();
$recipient->toAddress = Yii::app()->emailHelper->defaultTestToAddress;
$recipient->toName = 'Test Recipient';
$recipient->type = EmailMessageRecipient::TYPE_TO;
$emailMessage->recipients->add($recipient);
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
$validatedAndSaved = $emailMessage->save();
if (!$validatedAndSaved) {
throw new NotSupportedException();
}
Yii::app()->emailHelper->sendImmediately($emailMessage);
if (!$emailMessage->hasSendError()) {
$messageContent .= Zurmo::t('EmailMessagesModule', 'Message successfully sent') . "\n";
return true;
} else {
$messageContent .= Zurmo::t('EmailMessagesModule', 'Message failed to send') . "\n";
$messageContent .= $emailMessage->error . "\n";
$this->errorMessage = $messageContent;
return false;
}
}
示例14: testTooManySendAttemptsResultingInFailure
/**
* @depends testSendRealEmail
*/
public function testTooManySendAttemptsResultingInFailure()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
if (EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) {
//add a message in the outbox_error folder.
$emailMessage = EmailMessageTestHelper::createDraftSystemEmail('a test email 2', $this->user);
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_OUTBOX_ERROR);
$emailMessage->sendAttempts = 5;
$emailMessage->save();
$this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
$this->assertEquals(7, Yii::app()->emailHelper->getSentCount());
Yii::app()->emailHelper->sendQueued();
$this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
$this->assertEquals(7, Yii::app()->emailHelper->getSentCount());
$this->assertTrue($emailMessage->folder->isSame(EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_OUTBOX_FAILURE)));
} else {
$this->markTestSkipped();
}
}
示例15: sendEmailInviteToParticipant
/**
* @param Conversation $conversation
* @param $person
*/
public static function sendEmailInviteToParticipant(Conversation $conversation, $person)
{
assert('$conversation->id > 0');
assert('$person instanceof User || $person instanceof Contact');
if ($person->primaryEmail->emailAddress !== null) {
$userToSendMessagesFrom = $conversation->owner;
$emailMessage = new EmailMessage();
$emailMessage->owner = Yii::app()->user->userModel;
$emailMessage->subject = Zurmo::t('ConversationsModule', 'You have been invited to participate in a conversation');
$emailContent = new EmailMessageContent();
$emailContent->textContent = EmailNotificationUtil::resolveNotificationTextTemplate(static::getParticipantInviteEmailTextContent($conversation));
$emailContent->htmlContent = EmailNotificationUtil::resolveNotificationHtmlTemplate(static::getParticipantInviteEmailHtmlContent($conversation));
$emailMessage->content = $emailContent;
$sender = new EmailMessageSender();
$sender->fromAddress = Yii::app()->emailHelper->resolveFromAddressByUser($userToSendMessagesFrom);
$sender->fromName = strval($userToSendMessagesFrom);
$sender->personsOrAccounts->add($userToSendMessagesFrom);
$emailMessage->sender = $sender;
$recipient = new EmailMessageRecipient();
$recipient->toAddress = $person->primaryEmail->emailAddress;
$recipient->toName = strval($person);
$recipient->type = EmailMessageRecipient::TYPE_TO;
$recipient->personsOrAccounts->add($person);
$emailMessage->recipients->add($recipient);
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
try {
Yii::app()->emailHelper->send($emailMessage);
} catch (CException $e) {
//Not sure what to do yet when catching an exception here. Currently ignoring gracefully.
}
}
}