Skip to content

Commit

Permalink
Added attachments to adapters.
Browse files Browse the repository at this point in the history
  • Loading branch information
petrofcikmatus committed Oct 27, 2017
1 parent 59fc0a2 commit e32727a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/Adapter/Mailjet/MailjetAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ private function createMessage(MessageInterface $message)
if ($message->hasVariables()) {
$m['Variables'] = $message->getVariables();
}

if ($message->hasAttachments()) {
$m['Attachments'] = [];

foreach ($message->getAttachments() as $attachment) {
$m['Attachments'][] = [
'ContentType' => $attachment->getType(),
'Filename' => $attachment->getName(),
'Base64Content' => $attachment->getData(),
];
}
}
} else {
$m['HTMLPart'] = $message->getHtml();
$m['TextPart'] = $message->getText();
Expand Down
12 changes: 12 additions & 0 deletions src/Adapter/SparkPost/SparkPostAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ public function sendMail(MessageInterface $message)
if ($message->hasSubstitutionData()) {
$payload['substitution_data'] = $message->getSubstitutionData();
}

if ($message->hasAttachments()) {
$payload['attachments'] = [];

foreach ($message->getAttachments() as $attachment) {
$payload['attachments'][] = [
'type' => $attachment->getType(),
'name' => $attachment->getName(),
'data' => $attachment->getData(),
];
}
}
} else {
$payload['content']['html'] = $message->getHtml();
$payload['content']['text'] = $message->getText();
Expand Down
13 changes: 8 additions & 5 deletions src/Model/Attachment/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class Attachment implements AttachmentInterface
/**
* @var string
*/
protected $name = '';
protected $name = 'Attachment';

/**
* @var string
*/
protected $type = '';
protected $type = 'application/octet-stream';

/**
* @var string
Expand All @@ -33,11 +33,12 @@ public function getName()
}

/**
* Name of file.
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
$this->name = (string)$name;
}

/**
Expand All @@ -49,11 +50,12 @@ public function getType()
}

/**
* MIME type of file.
* @param string $type
*/
public function setType($type)
{
$this->type = $type;
$this->type = (string)$type;
}

/**
Expand All @@ -65,10 +67,11 @@ public function getData()
}

/**
* Base64 encoded file content.
* @param string $data
*/
public function setData($data)
{
$this->data = $data;
$this->data = (string)$data;
}
}

0 comments on commit e32727a

Please sign in to comment.