本文整理汇总了PHP中EmailMessage::save方法的典型用法代码示例。如果您正苦于以下问题:PHP EmailMessage::save方法的具体用法?PHP EmailMessage::save怎么用?PHP EmailMessage::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EmailMessage
的用法示例。
在下文中一共展示了EmailMessage::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
示例2: 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;
}
示例3: 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());
}
示例4: 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
示例5: resolveEmailMessage
protected function resolveEmailMessage($subject = 'Subject', $textContent = 'My First Message', $htmlContent = 'Some fake HTML content', $fromAddress = 'zurmo@zurmo.org', $fromName = 'Zurmo', $toAddress = 'bob.message@zurmotest.com', $toName = null, $contact = null)
{
if (!isset($contact)) {
$contact = ContactTestHelper::createContactByNameForOwner('emailContact', Yii::app()->user->userModel);
}
$emailMessage = new EmailMessage();
$emailMessage->owner = $contact->owner;
$emailMessage->subject = $subject;
$emailContent = new EmailMessageContent();
$emailContent->textContent = $textContent;
$emailContent->htmlContent = $htmlContent;
$emailMessage->content = $emailContent;
$sender = new EmailMessageSender();
$sender->fromAddress = $fromAddress;
$sender->fromName = $fromName;
$sender->personsOrAccounts->add(Yii::app()->user->userModel);
$emailMessage->sender = $sender;
$recipient = new EmailMessageRecipient();
$recipient->toAddress = $toAddress;
if (!isset($toName)) {
$toName = strval($contact);
}
$recipient->toName = $toName;
$recipient->personsOrAccounts->add($contact);
$recipient->type = EmailMessageRecipient::TYPE_TO;
$emailMessage->recipients->add($recipient);
$emailBox = EmailBoxUtil::getDefaultEmailBoxByUser(Yii::app()->user->userModel);
$emailMessage->folder = EmailFolder::getByBoxAndType($emailBox, EmailFolder::TYPE_OUTBOX);
$saved = $emailMessage->save();
if (!$saved) {
var_dump($emailMessage->getErrors());
throw new FailedToSaveModelException();
}
return $emailMessage;
}
示例6: sendEmail
protected static function sendEmail(Notification $notification)
{
if ($notification->owner->primaryEmail->emailAddress !== null && !UserConfigurationFormAdapter::resolveAndGetValue($notification->owner, 'turnOffEmailNotifications')) {
$userToSendMessagesFrom = BaseControlUserConfigUtil::getUserToRunAs();
$emailMessage = new EmailMessage();
$emailMessage->owner = Yii::app()->user->userModel;
$emailMessage->subject = strval($notification);
$emailContent = new EmailMessageContent();
$emailContent->textContent = EmailNotificationUtil::resolveNotificationTextTemplate($notification->notificationMessage->textContent);
$emailContent->htmlContent = EmailNotificationUtil::resolveNotificationHtmlTemplate($notification->notificationMessage->htmlContent);
$emailMessage->content = $emailContent;
$sender = new EmailMessageSender();
$sender->fromAddress = Yii::app()->emailHelper->resolveFromAddressByUser($userToSendMessagesFrom);
$sender->fromName = strval($userToSendMessagesFrom);
$emailMessage->sender = $sender;
$recipient = new EmailMessageRecipient();
$recipient->toAddress = $notification->owner->primaryEmail->emailAddress;
$recipient->toName = strval($notification->owner);
$recipient->type = EmailMessageRecipient::TYPE_TO;
$recipient->personsOrAccounts->add($notification->owner);
$emailMessage->recipients->add($recipient);
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
if (!$emailMessage->save()) {
throw new FailedToSaveModelException();
}
try {
Yii::app()->emailHelper->sendImmediately($emailMessage);
} catch (CException $e) {
//Not sure what to do yet when catching an exception here. Currently ignoring gracefully.
}
}
}
示例7: processMessageAsFailure
protected function processMessageAsFailure(EmailMessage $emailMessage)
{
$emailMessage->folder = EmailFolder::getByBoxAndType($emailMessage->folder->emailBox, EmailFolder::TYPE_OUTBOX_FAILURE);
$saved = $emailMessage->save();
if (!$saved) {
throw new FailedToSaveModelException();
}
}
示例8: 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;
}
}
示例9: actionLoadUnmatchedSampler
/**
* Special method to load archived, but unmatched emails. This is for use with the @see ArchivedEmailMatchingListView
*/
public function actionLoadUnmatchedSampler()
{
if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel)) {
throw new NotSupportedException();
}
$box = EmailBoxUtil::getDefaultEmailBoxByUser(Yii::app()->user->userModel);
//#1 Create Archived - Sent
$emailMessage = new EmailMessage();
$emailMessage->owner = Yii::app()->user->userModel;
$emailMessage->subject = 'A test unmatched archived sent email';
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'My First Message';
$emailContent->htmlContent = 'Some fake HTML content';
$emailMessage->content = $emailContent;
//Sending is current user (super)
$sender = new EmailMessageSender();
$sender->fromAddress = 'super@zurmotest.com';
$sender->fromName = 'Super User';
$sender->personOrAccount = Yii::app()->user->userModel;
$emailMessage->sender = $sender;
//Recipient is BobMessage
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'bob.message@zurmotest.com';
$recipient->toName = 'Bobby Bobson';
$recipient->type = EmailMessageRecipient::TYPE_TO;
$emailMessage->recipients->add($recipient);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_ARCHIVED_UNMATCHED);
$emailMessage->sentDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
$saved = $emailMessage->save();
if (!$saved) {
throw new NotSupportedException();
}
//#2 Create Archived - Received
$emailMessage = new EmailMessage();
$emailMessage->owner = Yii::app()->user->userModel;
$emailMessage->subject = 'A test unmatched archived received email';
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'My Second Message';
$emailContent->htmlContent = 'Some fake HTML content';
$emailMessage->content = $emailContent;
//Sending is current user (super)
$sender = new EmailMessageSender();
$sender->fromAddress = 'bob.message@zurmotest.com';
$sender->fromName = 'Bobby Bobson';
$emailMessage->sender = $sender;
//Recipient is BobMessage
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'super@zurmotest.com';
$recipient->toName = 'Super User';
$recipient->type = EmailMessageRecipient::TYPE_TO;
$recipient->personOrAccount = Yii::app()->user->userModel;
$emailMessage->recipients->add($recipient);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_ARCHIVED_UNMATCHED);
$emailMessage->sentDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
$saved = $emailMessage->save();
if (!$saved) {
throw new NotSupportedException();
}
}
示例10: actionLoadCampaignWithAllItemActivityTypes
/**
* Special method to load a campaign with all types of campaignItemActivity
*/
public function actionLoadCampaignWithAllItemActivityTypes()
{
if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel)) {
throw new NotSupportedException();
}
$emailBox = EmailBoxUtil::getDefaultEmailBoxByUser(Yii::app()->user->userModel);
$marketingList = new MarketingList();
$marketingList->name = 'Demo Marketing List';
$marketingList->save();
$campaign = new Campaign();
$campaign->marketingList = $marketingList;
$campaign->name = 'Campaign with all campaignItemActivity';
$campaign->subject = 'Demo for all types of campaignItemActivities';
$campaign->status = Campaign::STATUS_COMPLETED;
$campaign->sendOnDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
$campaign->supportsRichText = true;
$campaign->htmlContent = 'Demo content';
$campaign->fromName = 'Zurmo';
$campaign->fromAddress = 'zurmo@zurmo.org';
$campaign->enableTracking = true;
$saved = $campaign->save();
if (!$saved) {
throw new FailedToSaveModelException();
}
$contacts = Contact::getAll();
//Awaiting queue
$contact = $contacts[0];
$campaignItem = new CampaignItem();
$campaignItem->processed = true;
$campaignItem->campaign = $campaign;
$campaignItem->contact = $contact;
$campaignItem->unrestrictedSave();
//Contact is not subscribed
$contact = $contacts[1];
$marketingList->addNewMember($contact->id, true);
$campaignItem = new CampaignItem();
$campaignItem->processed = true;
$campaignItem->campaign = $campaign;
$campaignItem->contact = $contact;
$activity = new CampaignItemActivity();
$activity->person = $contact;
$activity->campaignItem = $campaignItem;
$activity->quantity = 1;
$activity->type = CampaignItemActivity::TYPE_SKIP;
$activity->save();
$campaignItem->unrestrictedSave();
//Skipped, both primary and secondary are opted out
$contact = $contacts[2];
$contact->primaryEmail->emailAddress = $contact->firstName . '1@zurmo.org';
$contact->primaryEmail->optOut = true;
$contact->secondaryEmail->emailAddress = $contact->firstName . '2@zurmo.org';
$contact->secondaryEmail->optOut = true;
$contact->save();
$marketingList->addNewMember($contact->id);
$campaignItem = new CampaignItem();
$campaignItem->processed = true;
$campaignItem->campaign = $campaign;
$campaignItem->contact = $contact;
$activity = new CampaignItemActivity();
$activity->person = $contact;
$activity->campaignItem = $campaignItem;
$activity->quantity = 1;
$activity->type = CampaignItemActivity::TYPE_SKIP;
$activity->save();
$campaignItem->unrestrictedSave();
//Skipped, primary is opted out but secondary is not
$contact = $contacts[3];
$contact->primaryEmail->emailAddress = $contact->firstName . '1@zurmo.org';
$contact->primaryEmail->optOut = true;
$contact->secondaryEmail->emailAddress = $contact->firstName . '2@zurmo.org';
$contact->secondaryEmail->optOut = false;
$contact->save();
$marketingList->addNewMember($contact->id);
$campaignItem = new CampaignItem();
$campaignItem->processed = true;
$campaignItem->campaign = $campaign;
$campaignItem->contact = $contact;
$activity = new CampaignItemActivity();
$activity->person = $contact;
$activity->campaignItem = $campaignItem;
$activity->quantity = 1;
$activity->type = CampaignItemActivity::TYPE_SKIP;
$activity->save();
$campaignItem->unrestrictedSave();
//Skipped, primary and secondary not set
$contact = $contacts[4];
$contact->primaryEmail = null;
$contact->secondaryEmail = null;
$contact->save();
$marketingList->addNewMember($contact->id);
$campaignItem = new CampaignItem();
$campaignItem->processed = true;
$campaignItem->campaign = $campaign;
$campaignItem->contact = $contact;
$activity = new CampaignItemActivity();
$activity->person = $contact;
$activity->campaignItem = $campaignItem;
//.........这里部分代码省略.........
示例11: makeEmailMessage
protected function makeEmailMessage(Contact $contact, $subject = null)
{
$interval = mt_rand(4, 35) * 86400;
if (!isset($subject)) {
$subject = 'A test archived sent email';
}
//#1 Create Archived - Sent
$emailMessage = new EmailMessage();
$emailMessage->setScenario('importModel');
$emailMessage->owner = $contact->owner;
$emailMessage->subject = $subject;
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'My First Message';
$emailContent->htmlContent = 'Some fake HTML content';
$emailMessage->content = $emailContent;
//Sending is current user (super)
$sender = new EmailMessageSender();
$sender->fromAddress = 'super@zurmotest.com';
$sender->fromName = 'Super User';
$sender->personsOrAccounts->add(Yii::app()->user->userModel);
$emailMessage->sender = $sender;
//Recipient is BobMessage
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'bob.message@zurmotest.com';
$recipient->toName = strval($contact);
$recipient->personsOrAccounts->add($contact);
$recipient->type = EmailMessageRecipient::TYPE_TO;
$emailMessage->recipients->add($recipient);
$emailMessage->folder = EmailFolder::getByBoxAndType($this->emailBox, EmailFolder::TYPE_SENT);
$emailMessage->createdDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - $interval);
$emailMessage->sentDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - $interval + mt_rand(0, 3) * 86400);
$emailMessage->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
$saved = $emailMessage->save();
if (!$saved) {
throw new FailedToSaveModelException();
}
$emailMessage = EmailMessage::getById($emailMessage->id);
AllPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($emailMessage, Group::getByName(Group::EVERYONE_GROUP_NAME));
$emailMessage->save();
return $emailMessage;
}
示例12: createArchivedUnmatchedSentMessage
public static function createArchivedUnmatchedSentMessage(User $user)
{
if ($user->primaryEmail->emailAddress == null) {
throw new NotSupportedException();
}
$box = EmailBoxUtil::getDefaultEmailBoxByUser($user);
$emailMessage = new EmailMessage();
$emailMessage->owner = Yii::app()->user->userModel;
$emailMessage->subject = 'A test unmatched archived sent email';
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'My First Message';
$emailContent->htmlContent = 'Some fake HTML content';
$emailMessage->content = $emailContent;
//Sending is current user (super)
$sender = new EmailMessageSender();
$sender->fromAddress = $user->primaryEmail->emailAddress;
$sender->fromName = strval($user);
$sender->personsOrAccounts->add(Yii::app()->user->userModel);
$emailMessage->sender = $sender;
//Recipient is BobMessage
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'bob.message@zurmotest.com';
$recipient->toName = 'Bobby Bobson';
$recipient->type = EmailMessageRecipient::TYPE_TO;
$emailMessage->recipients->add($recipient);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_ARCHIVED_UNMATCHED);
$saved = $emailMessage->save();
if (!$saved) {
throw new NotSupportedException();
}
return $emailMessage;
}
示例13: testCreateMultipleEmailMessageWithAttachments
public function testCreateMultipleEmailMessageWithAttachments()
{
$jane = User::getByUsername('jane');
$billy = User::getByUsername('billy');
$emailMessageIds = array();
for ($count = 0; $count < 5; $count++) {
$emailMessage = new EmailMessage();
$emailMessage->owner = $jane;
$emailMessage->subject = 'My Email with 2 Attachments';
$emailMessage->files->add(ZurmoTestHelper::createFileModel('testNote.txt'));
$emailMessage->files->add(ZurmoTestHelper::createFileModel('testPDF.pdf'));
//Set sender, and recipient, and content
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'My Second Message';
$emailMessage->content = $emailContent;
//Sending from jane
$sender = new EmailMessageSender();
$sender->fromAddress = 'jane@fakeemail.com';
$sender->fromName = 'Jane Smith';
$sender->personsOrAccounts->add($jane);
$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 not in a folder.
$this->assertTrue($emailMessage->folder->id < 0);
$box = EmailBox::resolveAndGetByName('JaneBox');
$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);
$emailMessageIds[] = $emailMessage->id;
unset($emailMessage);
ForgetAllCacheUtil::forgetAllCaches();
}
foreach ($emailMessageIds as $id) {
$emailMessage = EmailMessage::getById($id);
$this->assertEquals('My Email with 2 Attachments', $emailMessage->subject);
$this->assertEquals(2, $emailMessage->files->count());
unset($emailMessage);
ForgetAllCacheUtil::forgetAllCaches();
}
}
示例14: testMultipleRecipientsAndTypes
/**
* @depends testCreateAndSendEmailMessageWithAttachment
*/
public function testMultipleRecipientsAndTypes()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$billy = User::getByUsername('billy');
$jane = User::getByUsername('jane');
$sally = User::getByUsername('sally');
$jason = User::getByUsername('jason');
$this->assertEquals(3, count(EmailMessage::getAll()));
$emailMessage = new EmailMessage();
$emailMessage->owner = $jane;
$emailMessage->subject = 'My Third Email';
//Attempt to save without setting required information
$saved = $emailMessage->save();
$this->assertFalse($saved);
$compareData = array('folder' => array('name' => array('Name cannot be blank.'), 'emailBox' => array('name' => array('Name cannot be blank.'))), 'sender' => array('fromAddress' => array('From Address cannot be blank.')));
$this->assertEquals($compareData, $emailMessage->getErrors());
//Set sender, and recipient, and content
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'My Third Message';
$emailMessage->content = $emailContent;
//Sending from jane
$sender = new EmailMessageSender();
$sender->fromAddress = 'jane@fakeemail.com';
$sender->fromName = 'Jane Smith';
$sender->personOrAccount = $jane;
$emailMessage->sender = $sender;
//Recipient is billy.
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'billy@fakeemail.com';
$recipient->toName = 'Billy James';
$recipient->type = EmailMessageRecipient::TYPE_TO;
$recipient->personOrAccount = $billy;
$emailMessage->recipients->add($recipient);
//CC recipient is Sally
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'sally@fakeemail.com';
$recipient->toName = 'Sally Pail';
$recipient->type = EmailMessageRecipient::TYPE_CC;
$recipient->personOrAccount = $sally;
$emailMessage->recipients->add($recipient);
//BCC recipient is Jason
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'jason@fakeemail.com';
$recipient->toName = 'Jason Blue';
$recipient->type = EmailMessageRecipient::TYPE_BCC;
$recipient->personOrAccount = $jason;
$emailMessage->recipients->add($recipient);
//At this point the message is not in a folder.
$this->assertTrue($emailMessage->folder->id < 0);
$box = EmailBox::resolveAndGetByName('JaneBox');
$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);
//Now send the message.
Yii::app()->emailHelper->send($emailMessage);
}
示例15: updateFolderForEmailMessageWithORM
/**
* Update an email message's folder and save it using ORM
* @param EmailMessage $emailMessage
* @param EmailFolder $folder
* @param bool $validate
*/
protected static function updateFolderForEmailMessageWithORM(EmailMessage &$emailMessage, EmailFolder $folder, $validate = true)
{
$emailMessage->folder = $folder;
$saved = $emailMessage->save($validate);
return $saved;
}