0

I have installed MailCatcher in my Symofny 4.2 project.

I have configured it in my .env file:

MAILER_URL=http://127.0.0.1:1080/

And in swiftmailer.yml

swiftmailer:
    url: '%env(MAILER_URL)%'
    spool: { type: 'memory' }

parameters:
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    mailer_port: 1025

When I open that url, mail inbox loads correctly.

I trigger my __invoke function while persisting some entity and want to catch mail I am sending.

I am using API platform so it's tricky to find out where the problem is.

Here is an error:

enter image description here

Entity is peristed in the db but mail has not been send.

I tried changing the response but no luck. I am stuck with this error.

public function __invoke()
{
$transport = (new Swift_SmtpTransport('127.0.0.1', 1025));

    $mailer = new Swift_Mailer($transport);

    $message = (new \Swift_Message('Hello Email'))
        ->setFrom('send@example.com')
        ->setTo('recipient@example.com')
        ->setBody('My <em>name</em> is Filip', 'text/plain');

    $mailer->send($message);

    return new JsonResponse(['result' => 'ok']);
   }
}
  • I'm not seeing any code where you are setting your SMTP server. Where is this set? Is it using the correct port? (1025) – Peter B Aug 03 '20 at 10:40
  • I saw that all it needs is the MAILER_URL? Where the SMTP config should be stored? @PeterB – JohnnyBeGood Aug 03 '20 at 10:52
  • Within that URL. Theres an example including specifying the port here: https://symfony.com/doc/current/reference/configuration/swiftmailer.html – Peter B Aug 03 '20 at 10:57
  • I edited my post. Still no luck. @PeterB – JohnnyBeGood Aug 03 '20 at 11:27
  • `sendmail` does not utilise SMTP. Here's a link to building a transport: https://swiftmailer.symfony.com/docs/sending.html – Peter B Aug 03 '20 at 11:47
  • I am sorry for bothering you. I updated my post again with new configuration and new lines of code. Still no luck with receiving email. Am I missing something? @PeterB – JohnnyBeGood Aug 03 '20 at 12:43

0 Answers0