Skip to content

[Mailer] Sendgrid mailer transport does not respect custom ports #36224

Closed
@ftdysa

Description

@ftdysa

Symfony version(s) affected:
symfony/sendgrid-mailer v5.0.5

Description
The Sendgrid Smtp Transport does not respect custom ports provided in the DSN. From Sendgrid's documentation (https://sendgrid.com/docs/for-developers/sending-email/getting-started-smtp/), they suggest the following:

SendGrid accepts unencrypted and TLS connections on ports 25, 587, & 2525. You can also connect via SSL on port 465.

On inspection, it looks like this is how the various Smtp transports are setup so maybe this is an explicit design decision?

Also, it should be noted that you can get around this via something like:

$transport = Transport::fromDsn($dsn);
$transport->getStream()->setPort(587);

but this seems like it'd be nice for the library to handle for you since it already handles DSN parsing well.

How to reproduce
Test script

<?php

use Symfony\Component\Mailer\Bridge\Sendgrid\Transport\SendgridSmtpTransport;
use Symfony\Component\Mailer\Transport;

require 'vendor/autoload.php';

$dsn = 'sendgrid+smtp://apikey:SG.redacted@smtp.sendgrid.com:587';
$transport = Transport::fromDsn($dsn);
assert($transport instanceof SendgridSmtpTransport);

var_dump($transport->getStream()->getPort());

Output:

fred@home:~/projects/symfony$ php test.php 
/home/fred/projects/symfony/test.php:13:
int(465)

Possible Solution
Ideally, this should probably be parsed and injected here https://github.com/symfony/sendgrid-mailer/blob/master/Transport/SendgridTransportFactory.php#L36, so that we can pass it down to EsmtpTransport which handles the defaults (https://github.com/symfony/mailer/blob/master/Transport/Smtp/EsmtpTransport.php) but that doesn't really leave us with a lovely constructor for SendgridSmtpTransport.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions