postalsys/emailengine

How to send email using smtp gateway

Niba-nazar opened this issue · 5 comments

Hi,

I have added AWS SMTP gateway details on my email engine application. However, am not sure how to send emails using those AWS SMTP details. I have tried to send emails using the email templates and getting account id not found error. Could you please help me with this?

image

With EmailEngine, all sent emails are bound to some specific email account, and that email account would be the "sender" of the email.

So, you would have to add an email account to EmailEngine first, and when sending emails, you submit the email as that account but specify the SMTP gateway to be used for delivery.

Example. Normally, when sending as the account "example" the submission API request would look like this:

curl -XPOST "http://127.0.0.1:3000/v1/account/example/submit" \
    -H "Authorization: Bearer f77cf263b70488c...." \
    -H "Content-type: application/json" \
    -d '{
      "to": {
        "name": "Ethereal",
        "address": "andris@ethereal.email"
      },
      "subject": "Test message",
      "text": "Hello world!"
    }'

This email would be sent to the account's SMTP server.

On the other hand, if you have created a gateway, let's say with ID "aws", then you would have to specify a "gateway" property. In this case, the email would not be sent to the account's SMTP server, but to the gateway SMTP (in this case, to AWS STMP).

curl -XPOST "http://127.0.0.1:3000/v1/account/example/submit" \
    -H "Authorization: Bearer f77cf263b70488c...." \
    -H "Content-type: application/json" \
    -d '{
      "to": {
        "name": "Ethereal",
        "address": "andris@ethereal.email"
      },
      "subject": "Test message",
      "text": "Hello world!",
      "gateway": "aws"
    }'

In both cases the same additional actions would be taken, for example the sent email would be uploaded to the Sent Mail folder of the account with ID "example" etc.

So, in short, in your case, do not set the gateway id as the ID value in the test send form, but the ID of an email account you have registered with EmailEngine.

Hi,

Thanks for the reply @andris9 . I sent emails using the email account I have added. However, still facing issue while trying to send emails using aws smtp. Getting the error below. Is there anything am missing out while setting up aws smtp details as SMTP gateway?

image

It means something is wrong, and EmailEngine was not able to submit the email to the SMTP server. You can see the details if you tail the application logs from EmailEngine. This should give you a specific error response for the delivery attempt. For example, maybe the mail port was firewalled, or DNS failed, or the SMTP server rejected your email because you were using a From address that was not whitelisted or whatever. In any case, EmailEngine tried to deliver that email but failed.

Hi,
Could you please let me know why my added smtp gateway status is showing as not used? what could be the status when it is actually in use? active ?

The status changes once you have sent at least 1 email with that gateway with the message submit API https://api.emailengine.app/#tag/Submit