How to setup my SMTP settings?

fabrice.dhuicque
fabrice.dhuicque Spryker Solution Partner Posts: 19 🧑🏻‍🚀 - Cadet

Hi!

I have some troubles to set up my SMTP constants in my app.

I've edited my deploy.project.preprod.yml file end added this stuff:

environment: docker.prodimage:
tag: spryker/php:8.1
environment:
SPRYKER_DEFAULT_STORE: "FR"
SPRYKER_ACTIVE_STORES: "FR"
SPRYKER_HOOK_BEFORE_DEPLOY: "vendor/bin/install -r EU/pre-deploy -vvv"
SPRYKER_HOOK_AFTER_DEPLOY: "true"
SPRYKER_HOOK_INSTALL: "vendor/bin/install -r EU/production --no-ansi -vvv"
SPRYKER_HOOK_DESTRUCTIVE_INSTALL: "vendor/bin/install -r EU/destructive --no-ansi -vvv"
SPRYKER_PRODUCT_CONFIGURATOR_HOST: date-time-configurator.mydomainname.com
SPRYKER_PRODUCT_CONFIGURATOR_PORT: 443
SPRYKER_SMTP_HOST: "email-smtp.eu-west-3.amazonaws.com"
SPRYKER_SMTP_PORT: 587
SPRYKER_SMTP_ENCRYPTION: 'tls'
SPRYKER_SMTP_AUTH_MODE: 'plain'
SPRYKER_SMTP_USERNAME: "aws-provided-username"
SPRYKER_SMTP_PASSWORD: "aws-provided-password"
SPRYKER_MAIL_SENDER_EMAIL: "sender@email.com"
SPRYKER_MAIL_SENDER_NAME: "sender name"

And I also removed mailhog part from it.

I also edited config_default.php and config_default-docker.php to put my constants to the proper value.


When I run docker/sdk boot deploy.project.preprod.yml, in generated .env files, all are setup with:
SPRYKER_SMTP_HOST=mail_catcher
SPRYKER_SMTP_PORT=1025

I don't have anywhere in my codebase something else about SPRYKER_SMTP_HOST and PORT. Everywhere they appear I've put my real values, can you tell me what am I missing about that ?

Thank you for help.

Best Answer

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,081 ⚖️ - Guardians (admin)
    Answer ✓

    So if you remove it from the deploy file AND adjust the config-file it does not work?

    Do you think that if I simply remove the mail_catcher part from our
    deploy file (in our staging branch, the deploy file contains this part) I
    don't need to edit the SMTP constants and it will get them from AWS
    environment?

    At least this is the information I have so far. Are you using the Spryker Cloud?

Answers

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,081 ⚖️ - Guardians (admin)

    Hehey @fabrice.dhuicque ,

    You need to do two things.

    1. Remove the service from the deploy file:
    mail_catcher:
        engine: mailhog
        endpoints:
            mail.spryker.local:
    

    2. Adjust your project configuration:

    // >>> SYMFONY_MAILER
    $config[SymfonyMailerConstants::SMTP_HOST] = getenv('SPRYKER_SMTP_HOST') ?: null;
    $config[SymfonyMailerConstants::SMTP_PORT] = getenv('SPRYKER_SMTP_PORT') ?: null;
    $config[SymfonyMailerConstants::SMTP_ENCRYPTION] = getenv('SPRYKER_SMTP_ENCRYPTION') ?: null;
    $config[SymfonyMailerConstants::SMTP_AUTH_MODE] = getenv('SPRYKER_SMTP_AUTH_MODE') ?: null;
    $config[SymfonyMailerConstants::SMTP_USERNAME] = getenv('SPRYKER_SMTP_USERNAME') ?: null;
    $config[SymfonyMailerConstants::SMTP_PASSWORD] = getenv('SPRYKER_SMTP_PASSWORD') ?: null;
    

    I have a follow-up question for you: why do you need to define another smtp server by yourself? Normally Spryker is taking care of this as far as i know.

    All the best,
    Florian

  • fabrice.dhuicque
    fabrice.dhuicque Spryker Solution Partner Posts: 19 🧑🏻‍🚀 - Cadet

    Thank you for your answer, I've tried to do your solution some days ago, but this didn't work. I've finally found that I created a config_local.php file (to avoid to expose credentials on our VCS) and in that file I forced to override value (removing ternary operator).

    Your question is interesting, I don't know why I need to do that, but the fact is that the mails don't work in our Staging nor Production environments.

    Do you think that if I simply remove the mail_catcher part from our deploy file (in our staging branch, the deploy file contains this part) I don't need to edit the SMTP constants and it will get them from AWS environment? It could be fine ^^

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,081 ⚖️ - Guardians (admin)
    Answer ✓

    So if you remove it from the deploy file AND adjust the config-file it does not work?

    Do you think that if I simply remove the mail_catcher part from our
    deploy file (in our staging branch, the deploy file contains this part) I
    don't need to edit the SMTP constants and it will get them from AWS
    environment?

    At least this is the information I have so far. Are you using the Spryker Cloud?

  • fabrice.dhuicque
    fabrice.dhuicque Spryker Solution Partner Posts: 19 🧑🏻‍🚀 - Cadet
    edited September 2023

    If I remove mail_catcher from deploy file and adjust config_default file with the ternary operator, i get an error involving the mail_catcher. If i remove the ternary operator and put '$config[SymfonyMailerConstants::SMTP_HOST] = "my-host";' for each constant, it works.

    But if I do that, I need to expose credentials on our VCS which is not a best practice ^^

    "At least this is the information I have so far. Are you using the Spryker Cloud?"

    Yes, we use it, but for my tests I'm trying in local adding staging addresses to my etc/hosts.

    Next time we update our staging environment, I'll try that simple way.

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,081 ⚖️ - Guardians (admin)

    But if I do that, I need to expose credentials on our VCS which is not a best practice ^^

    ah yeah, sorry, i mixed different requirements. I thought you want to test it locally. so for that of course you use the local config which does not get committed. But in deployed systems you would set this normally via environment variables setup via the cloud system. in both cases the entry of the mail_catcher service has to be removed from the deploy-file.

  • fabrice.dhuicque
    fabrice.dhuicque Spryker Solution Partner Posts: 19 🧑🏻‍🚀 - Cadet

    OK, so finally, I've just updated our environment and tested SMTP. So the solution was too obvious for me and as you said, the Mail Catcher removal is enough to make SMTP working 💪

    Thank you so much!