Coder Social home page Coder Social logo

resend-laravel's Introduction

Resend for Laravel

Tests Packagist Downloads Packagist Version License


Provides Resend integration for Laravel and Symfony Mailer.

Requires PHP 8.1+

Examples

Send an email with:

Getting started

First install Resend for Laravel via the Composer package manager:

composer require resend/resend-laravel

Next, you should configure your Resend API key in your application's .env file:

RESEND_API_KEY=re_123456789

Finally, you may use the Resend facade to access the Resend API:

use Resend\Laravel\Facades\Resend;

Resend::emails()->send([
    'from' => '[email protected]',
    'to' => '[email protected]',
    'subject' => 'hello world',
    'text' => 'it works!',
]);

Using Resend's Laravel mailer

Resend for Laravel comes bundled with a Laravel mailer to make it easier to send emails. To start using the Resend mail transport, first create a new mailer definition within your application's config/mail.php configuration file:

'resend' => [
    'transport' => 'resend',
],

Note The Resend mailer will use the RESEND_API_KEY in your application's .env file.

Finally, update the MAIL_MAILER environment variable to use resend:

MAIL_MAILER=resend

resend-laravel's People

Contributors

emersonlaurentino avatar icegreeen avatar jayanratna avatar renovate[bot] avatar zenorocha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

resend-laravel's Issues

Intermittent Syntax Error in ResendTransportFactory when Sending Emails

Description

We are experiencing an intermittent syntax error when attempting to send emails using the ResendTransportFactory. This issue does not occur on all requests, suggesting some conditionality in the error's appearance.

Error Details

The error message is as follows:

}[2024-06-07 00:52:59] local.ERROR: Syntax error {"exception":"[object] (Exception(code: 0): Syntax error at vendor/resend/resend-laravel/src/Transport/ResendTransportFactory.php:73)
[stacktrace]

File: resend-laravel/src/Transport/ResendTransportFactory.php
Line: 73

Occurrence

This error seems to be occurring randomly, as it does not appear with every email sending attempt. It might be related to specific conditions or data inputs that are not yet clearly identified.

Steps to Reproduce

  1. Initiate the email sending process through ResendTransportFactory.
  2. Occasionally, the syntax error occurs without clear reproducibility patterns.

Argument #2 ($value) must be of type string, null given

I'm getting this error from time to time:

Symfony\Component\Mime\Header\Headers::addTextHeader(): Argument #2 ($value) must be of type string, null given, called in /vendor/symfony/mime/Header/Headers.php on line 152

This is triggered by vendor/resend/resend-laravel/src/Transport/ResendTransportFactory.php:โ€‰66

Ignored Resend rate limiting, Laravel failover configuration doesn't work

Intro

Hello there,

We experienced many issues with this package, because it is simply ignoring the rate limitation of Resend.

By default, Resend has a rate limit of 2 requests per second for API calls. 1 This rate limit is designed to manage the load on their API and ensure fair usage across all customers.

However, Resend understands that some users may need higher rate limits for their specific use cases. If you find that the default rate limit is not sufficient for your needs, you have the option to request an increase. To request a rate limit increase, you should contact Resend support. Here's what you need to know:

The default rate limit can be increased for trusted senders upon request. 2. If you have specific requirements that exceed the default limit, you should reach out to Resend support to discuss your needs. 3. You can contact Resend support through their website at https://resend.com/contact to request a rate increase. It's worth noting that Resend provides response headers that help you monitor your current rate limit usage. These headers include:

  • ratelimit-limit: Maximum number of requests allowed within a window
  • ratelimit-remaining: How many requests you have left within the current window
  • ratelimit-reset: How many seconds until the limits are reset
  • retry-after: How many seconds you should wait before making a follow-up request These headers can help you manage your API requests and avoid hitting the rate limit.

If you do exceed the rate limit, you'll receive a 429 response error code. To prevent this, Resend recommends implementing strategies such as introducing a queue mechanism or reducing the number of concurrent requests per second. Remember, while requesting a rate limit increase is possible, it's also important to optimize your API usage to work efficiently within the provided limits when possible.

We are using a "Failover" configuration in Laravel 11.

'failover' => [
  'transport' => 'failover',
  'mailers' => [
    'resend',
    'smtp',
    'log',
  ],
],

Expected behaviour

I expect when I want to send out E-Mails using Resend mail driver in Laravel, it should work. If Resend has a built-in 2 requests per second rate limit, and also rate limit information response headers, the package should be prepared to read and use this information, and send out the mails via Resend correctly.

Also, if the requests fails, Laravel should use the next E-Mail sending method configured in the failover configuration. I am not sure that this is a Laravel issue or a Resend package issue, but it doesn't work right now, if the response is 429 from Resend, Laravel won't try to send out with the next configured E-Mail sender.

Issue description, screenshots

So we just released a webshop with around 15.000 users and wanted to send them a Password Change E-Mail. However, this resulted with a disaster that the Resend API responded with 429 in many cases, and Laravel didn't try to send it out with the failover SMTP server, it just threw an error... ๐Ÿ‘Ž
Screenshot 2024-06-27 at 10 06 42
Screenshot 2024-06-27 at 16 23 02

Add tests

Important!

Add tests for the package to ensure developers have a stable experience. Local testing isn't enough.

Add documentation

Documentation is required on how to configure the resend mail transport for a Laravel application.

File Attachments not sent

Hello Team,

I noticed that email attachments are not being forwarded using the laravel library. I think this is something that the library should address.

Regards,
Runo

Add documentation for webhooks

The Resend documentation requires additional docs on how to use the webhook feature built into Resend for Laravel.

Currently the webhook route is configured to be: /resend/webhook which dispatches Laravel events based on the webhook event received from Resend.

Laravel Integration Error.

I have followed the defined instructions for Laravel-Resend and am seeing this error when attempting to send a raw email .
TYPE ERROR Symfony\Component\Mime\Header\Headers::addTextHeader(): Argument #2 ($value) must be of type string, null given,

Older Laravel versions

Hi Guys ๐Ÿ‘‹๐Ÿพ ,
Is there any chance of getting resend to work with older Laravel versions, 8, for example?

This is what I get for installing on a Laravel ^8.0:

~ composer require resend/resend-laravel
./composer.json has been updated
Running composer update resend/resend-laravel
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - resend/resend-laravel[dev-main, v0.1.0, ..., v0.5.0, 1.x-dev] require illuminate/support ^9.21|^10.0 -> found illuminate/support[v9.21.0, ..., 9.x-dev, v10.0.0, ..., 10.x-dev] but these were not loaded, likely because it conflicts with another require.
    - Root composer.json requires resend/resend-laravel * -> satisfiable by resend/resend-laravel[dev-main, v0.1.0, ..., v0.5.0, 1.x-dev].

You can also try re-running composer require with an explicit version constraint, e.g. "composer require resend/resend-laravel:*" to figure out if any version is installable, or "composer require resend/resend-laravel:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Unable to install

Hi,

I am getting this error.

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - resend/resend-laravel[v0.1.0, ..., v0.1.1] require resend/client ^0.1.1 -> could not be found in any version, there may be a typo in the package name.
    - resend/resend-laravel v0.1.2 requires resend/client ^0.2.0 -> could not be found in any version, there may be a typo in the package name.
    - resend/resend-laravel[dev-main, v0.1.3, ..., v0.5.0, 1.x-dev] require symfony/mailer ^6.2 -> found symfony/mailer[v6.2.0-BETA1, ..., 6.4.x-dev] but the package is fixed to v6.0.17 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - Root composer.json requires resend/resend-laravel * -> satisfiable by resend/resend-laravel[dev-main, v0.1.0, ..., v0.5.0, 1.x-dev].

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
 - It's a private package and you forgot to add a custom repository to find it

Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
You can also try re-running composer require with an explicit version constraint, e.g. "composer require resend/resend-laravel:*" to figure out if any version is installable, or "composer require resend/resend-laravel:^2.1" if you know which you need.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

composer
composer.json
  • php ^8.1
  • illuminate/http ^10.0|^11.0
  • illuminate/support ^10.0|^11.0
  • resend/resend-php ^0.12.0
  • symfony/mailer ^6.2|^7.0
  • friendsofphp/php-cs-fixer ^3.14
  • mockery/mockery ^1.5
  • orchestra/testbench ^8.17|^9.0
  • pestphp/pest ^2.0
github-actions
.github/workflows/tests.yml
  • actions/checkout v4
  • shivammathur/setup-php v2
  • actions/cache v4
  • ubuntu 22.04

  • Check this box to trigger a request for Renovate to run again on this repository

Unsupported mail transport [resend].

Not sure what I miss..

Error:
image

mail.php

    'mailers' => [
        'resend' => [
            'transport' => 'resend',
        ],
        'smtp' => [
            'transport' => 'smtp',
            'url' => env('MAIL_URL'),
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'local_domain' => env('MAIL_EHLO_DOMAIN'),
        ],

        'ses' => [
            'transport' => 'ses',
        ],
...

.env:
image

composer:
image

Typo in the official docs

Hi!
I recently integrated Resend into my PaaS and it works like a charm - thanks for such an accessible DX.
I noticed just one thing because it gave me a little bit of an headache - in the official docs for laravel under this url: https://resend.com/docs/send-with-laravel in the "Using the Resend Facade" section there's a typo in the class' method.
Resend::emails() is the correct syntax and on the website we can see a Resend::email() which results in a laravel error.
I dont know if its the right place to report this minor issue - if its not then please let me know so I can go and let the right person know :D

Once again, thanks for such a great laravel integration even if it's a niche

Add support for webhooks

  • Add a POST /resend/webhook route, handled using WebhookController@handle.
  • Add provision for webhook secret verification middleware. (There is currently no Resend feature for this).
  • handle method in controller should transform the event name so it can be handled. Eg. email.sent -> handleEmailSent.
  • Each events handle method should dispatch a Laravel Event: EmailSent/EmailDelivered/EmailDeliveryDelayed/EmailComplained/EmailBounced/EmailOpened/EmailClicked.
  • The developer can then handle the event using a Laravel listener, and the controller will automatically respond with a 200 status to Resend servers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.