-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCampaignSending.php
More file actions
117 lines (105 loc) · 3.87 KB
/
CampaignSending.php
File metadata and controls
117 lines (105 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace Netpeople\JangoMailBundle;
use Netpeople\JangoMailBundle\AbstractSending;
use Netpeople\JangoMailBundle\Emails\EmailInterface;
use Netpeople\JangoMailBundle\Exception\CampaignException;
use SoapFault;
/**
* Description of CampaignSending
*
* @author manuel
*/
class CampaignSending extends AbstractSending
{
public function getParametersToSend()
{
$config = $this->jangoMail->getConfig();
$toGroups = array();
foreach ($this->email->getGroups() as $group) {
$toGroups[] = $group->getName();
}
return array(
'FromEmail' => $config['fromemail'],
'FromName' => $config['fromname'],
'ToGroups' => join(',', $toGroups),
'ToGroupFilter' => '', //por ahora nada
'ToOther' => '', //por ahora nada
'ToWebDatabase' => '', //por ahora nada
'Subject' => $this->email->getSubject(),
'MessagePlain' => strip_tags($this->email->getMessage()),
'MessageHTML' => $this->email->getMessage(),
'Options' => $this->getOptionsString(),
);
}
public function send()
{
$result = false;
if (!($this->email instanceof EmailInterface)) {
throw new CampaignException('Debe llamar a setEmail() antes de hacer el Envío');
}
if (!count($this->email->getGroups())) {
throw new CampaignException('Debe agregar al menos un grupo antes de hacer el Envío');
}
$this->email->setOptions($this->prepareOptions());
try {
//si está desabilitado el envio, lo enviamos como transactional
//a un correo test
if (true === $this->jangoMail->getConfig('disable_delivery')) {
return $this->jangoMail->getTransactional()
->setEmail($this->email)->send();
}
$response = $this->jangoMail
->call('SendMassEmail', $this->getParametersToSend());
$response = preg_split('/\n/m', $response->SendMassEmailResult);
if (0 == $response[0]) {
$this->email->setEmailID($response[2]);
$result = $this->email;
} else {
$this->jangoMail->setError("No se pudo enviar el Correo (Asunto: {$this->email->getSubject()})");
}
} catch (SoapFault $e) {
$this->jangoMail->setError($e->getMessage());
$this->jangoMail->addEmailLog($this->email, 'ERROR');
throw new CampaignException($e->getMessage(), $e->getCode(), $e);
}
$this->jangoMail->addEmailLog($this->email, $result ? 'SUCCESS' : 'ERROR');
return $result;
}
public function getValidOptions()
{
return array(
'ReplyTo' => null,
'BCC' => null,
'CharacterSet' => null,
'Encoding' => null,
'Priority' => null,
'NoDuplicates' => null,
'UseSystemMAILFROM' => null,
'Receipt' => null,
'Wrapping' => null,
'ClickTrack' => null,
'OpenTrack' => null,
'NoClickTrackText' => null,
'SendDate' => null,
'ThrottlingNumberEmails' => null,
'ThrottlingNumberMinutes' => null,
'DoNotSendTo' => null,
'SuppressionGroups' => null,
'Triggers' => null,
'EmbedImages' => null,
'Attachment1' => null,
'Attachment2' => null,
'Attachment3' => null,
'Attachment4' => null,
'Attachment5' => null,
'SMS' => null,
'Template' => null,
'CustomCampaignID' => null,
'PreprocessNow' => null,
'PreprocessOnly' => null,
'TransactionalGroupID' => null,
'CC' => null,
'SkipUnsubCheck' => null,
);
}
}