Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
toEmail example
$host
=
$endpoint
[
'host'
]
.
(
$endpoint
[
'port'
]
?? null ? ':'.
$endpoint
[
'port'
]
: ''
)
;
}
else
{
$host
=
$configuration
->
get
(
'region'
)
;
}
return
sprintf
(
'ses+api://%s@%s',
$configuration
->
get
(
'accessKeyId'
)
,
$host
)
;
}
protected
function
getRequest
(
SentMessage
$message
)
: SendEmailRequest
{
try
{
$email
= MessageConverter::
toEmail
(
$message
->
getOriginalMessage
(
)
)
;
}
catch
(
\Exception
$e
)
{
throw
new
RuntimeException
(
sprintf
(
'Unable to send message with the "%s" transport: ', __CLASS__
)
.
$e
->
getMessage
(
)
, 0,
$e
)
;
}
if
(
$email
->
getAttachments
(
)
)
{
return
parent::
getRequest
(
$message
)
;
}
$envelope
=
$message
->
getEnvelope
(
)
;
$request
=
[
use
Symfony\Component\Mime\Email;
use
Symfony\Component\Mime\Message;
use
Symfony\Component\Mime\MessageConverter;
use
Symfony\Component\Mime\Part\DataPart;
class
MessageConverterTest
extends
TestCase
{
public
function
testToEmail
(
)
{
$file
=
file_get_contents
(
__DIR__.'/Fixtures/mimetypes/test.gif'
)
;
$email
=
(
new
Email
(
)
)
->
from
(
'
[email protected]
'
)
->
to
(
'
[email protected]
'
)
;
$this
->
assertSame
(
$email
, MessageConverter::
toEmail
(
$email
)
)
;
$this
->
assertConversion
(
(
clone
$email
)
->
text
(
'text content'
)
)
;
$this
->
assertConversion
(
(
clone
$email
)
->
html
(
'HTML content <img src="cid:test.jpg" />'
)
)
;
$this
->
assertConversion
(
(
clone
$email
)
->
text
(
'text content'
)
->
html
(
'HTML content <img src="cid:test.jpg" />'
)
)
;
$this
->
assertConversion
(
(
clone
$email
)
->
text
(
'text content'
)
->
html
(
'HTML content <img src="cid:test.jpg" />'
)
->
addPart
(
(
new
DataPart
(
$file
, 'test.jpg', 'image/gif'
)
)
->
asInline
(
)
)
)
;
/** * @author Fabien Potencier <
[email protected]
> */
abstract
class
AbstractApiTransport
extends
AbstractHttpTransport
{
abstract
protected
function
doSendApi
(
SentMessage
$sentMessage
, Email
$email
, Envelope
$envelope
)
: ResponseInterface;
protected
function
doSendHttp
(
SentMessage
$message
)
: ResponseInterface
{
try
{
$email
= MessageConverter::
toEmail
(
$message
->
getOriginalMessage
(
)
)
;
}
catch
(
\Exception
$e
)
{
throw
new
RuntimeException
(
sprintf
(
'Unable to send message with the "%s" transport: ', __CLASS__
)
.
$e
->
getMessage
(
)
, 0,
$e
)
;
}
return
$this
->
doSendApi
(
$message
,
$email
,
$message
->
getEnvelope
(
)
)
;
}
/** * @return Address[] */
protected
function
getRecipients
(
Email
$email
, Envelope
$envelope
)
: array
{