Search code examples
sparkpost

Routing mail through SMTP and also using API


I have an app (SaaS – Laravel/PHP) built and my goal is to send transactional mails through the app and also send general emails out through my app. My transactional mail is working via my sending domain (configured using spark post’s api-php).

Now, I want to configure my system so that a user logging in can also send out an emails via his/her own email address (which is also his/her username used to log in); I’m thinking that their message would just route through my sending domain (the ”from header” would be something like from users email via my sending domain).

Do I set up SMTP relay in addition to the job class I’ve created with sparkpost’s API ? Do I configure everything into sparkpost’s api; I am not sure how to approach this problem. Has any one encountered the same issue/found a solution?


Solution

  • Offering a general email sending service is a fairly broad topic. Here are some basic observations based on your question.

    Full disclosure: I work for SparkPost.

    In summary, you could use SparkPost or your own SMTP relay to send your user mail with some caveats. IMO, using an API-driven service would be simpler to manage than an SMTP relay server.

    From Addresses

    First it's important to recognise the risk of sending mail from customer domains without explicit authorisation from the domain owners. Modern email domains use several mechanisms (SPF, DKIM, DMARC, ...) to ensure that only authorised parties can send mail on their behalf. Without these mechanisms, anyone could impersonate anyone else over email.

    For that reason, I recommend you don't send mail from customer email addresses. Instead you could use your own domain either with a generic address like usermail@yourdomain.com or with your user email addresses embedded.

    Sending General Mail

    The messages your users send through your service will impact your reputation as an email sender. I recommend considering ways to provide your service while not presenting an easy, automatable, sending service for spammers. That might include limiting the types of message, speed or volume which people can send, including reCAPTCHA on mailing forms or possibly vetting users before letting them use mailing services.

    SparkPost Details

    The mail you send through SparkPost must using a sending domain which you control. Since SparkPost manages delivery, any mail sent through your SparkPost account will impact your account's reputation so unwanted mail could cause your account to be suspended. You might consider using subaccounts to separate each of your users' email traffic and understanding how suppression lists protects SparkPost accounts could also be useful.

     SMTP Relay Details

    That same caveats in the SparkPost Details notes apply here but you'll have to manage your relationship with each receiving domain (live.com, gmail, etc) directly. Your app will also have to include the usual unsubscribe and bounce handling features.