Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Resend with Example
# Resend with Symfony

This example shows how to use Resend with [Example](https://example.com).
This example shows how to use Resend with [Symfony](https://symfony.com).

> [!NOTE]
> This application uses Symfony 7.1 RC1. It will be updated to the stable version once it's released.

## Prerequisites

Expand All @@ -11,20 +14,38 @@ To get the most out of this guide, you’ll need to:

## Instructions

1. Replace `re_123456789` on `example.ts` with your API key.
1. Go to `./application` directory

2. Create a `.env.local` file and paste `MAILER_DSN=resend+api://API_KEY@default` then replace `API_KEY` with your API key.

2. Install dependencies:
3. Install dependencies:

```sh
TBD
composer install
```

3. Execute the following command:
4. Start the server:

```sh
TBD
symfony serve -d
```

5. Open your browser and go to `https://127.0.0.1:8000/`

6. Click on the button to send an email.

## Instruction for webhook

1. Expose your local server to the internet using [expose.dev](https://expose.dev).

2. Register your webhook URL (`{EXPOSE_URL}/webhook/mailer_resend`) in [Resend settings](https://resend.com/webhooks). Check the wanted events.

3. Paste `MAILER_RESEND_SECRET=SECRET_KEY` on `.env.local` and replace `SECRET_KEY` with your webhook signing secret you get after registering the webhook in Resend.

4. Click on the button to send an email.

5. Go to `https://127.0.0.1:8000/email-statuses` to see received events (stored in `var/emails.json`)

## License

MIT License
MIT License
43 changes: 43 additions & 0 deletions application/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
# https://symfony.com/doc/current/configuration/secrets.html
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=a0afac6902adc3c7456d6b5535403dc6
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
DATABASE_URL="postgresql://app:[email protected]:5432/app?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###

###> symfony/messenger ###
# Choose one of the transports below
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0
###< symfony/messenger ###

###> symfony/resend-mailer ###
MAILER_DSN=resend+api://API_KEY@default
###< symfony/resend-mailer ###

MAILER_RESEND_SECRET=SECRET_KEY
6 changes: 6 additions & 0 deletions application/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
25 changes: 25 additions & 0 deletions application/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###

###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###

###> symfony/phpunit-bridge ###
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###

###> symfony/asset-mapper ###
/public/assets/
/assets/vendor/
###< symfony/asset-mapper ###
10 changes: 10 additions & 0 deletions application/assets/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import './bootstrap.js';
/*
* Welcome to your app's main JavaScript file!
*
* This file will be included onto the page via the importmap() Twig function,
* which should already be in your base.html.twig.
*/
import './styles/app.css';

console.log('This log comes from assets/app.js - welcome to AssetMapper! 🎉');
5 changes: 5 additions & 0 deletions application/assets/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { startStimulusApp } from '@symfony/stimulus-bundle';

const app = startStimulusApp();
// register any custom, 3rd party controllers here
// app.register('some_controller_name', SomeImportedController);
15 changes: 15 additions & 0 deletions application/assets/controllers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"controllers": {
"@symfony/ux-turbo": {
"turbo-core": {
"enabled": true,
"fetch": "eager"
},
"mercure-turbo-stream": {
"enabled": false,
"fetch": "eager"
}
}
},
"entrypoints": []
}
16 changes: 16 additions & 0 deletions application/assets/controllers/hello_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Controller } from '@hotwired/stimulus';

/*
* This is an example Stimulus controller!
*
* Any element with a data-controller="hello" attribute will cause
* this controller to be executed. The name "hello" comes from the filename:
* hello_controller.js -> "hello"
*
* Delete this file or adapt it for your use!
*/
export default class extends Controller {
connect() {
this.element.textContent = 'Hello Stimulus! Edit me in assets/controllers/hello_controller.js';
}
}
4 changes: 4 additions & 0 deletions application/assets/styles/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
color: whitesmoke;
background-color: black;
}
21 changes: 21 additions & 0 deletions application/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

if (!is_dir(dirname(__DIR__).'/vendor')) {
throw new LogicException('Dependencies are missing. Try running "composer install".');
}

if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

return new Application($kernel);
};
23 changes: 23 additions & 0 deletions application/bin/phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env php
<?php

if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}

if (is_file(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
if (PHP_VERSION_ID >= 80000) {
require dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit';
} else {
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__).'/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
PHPUnit\TextUI\Command::main();
}
} else {
if (!is_file(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
}

require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
}
19 changes: 19 additions & 0 deletions application/compose.override.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3'

services:
###> doctrine/doctrine-bundle ###
database:
ports:
- "5432"
###< doctrine/doctrine-bundle ###

###> symfony/mailer ###
mailer:
image: axllent/mailpit
ports:
- "1025"
- "8025"
environment:
MP_SMTP_AUTH_ACCEPT_ANY: 1
MP_SMTP_AUTH_ALLOW_INSECURE: 1
###< symfony/mailer ###
26 changes: 26 additions & 0 deletions application/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3'

services:
###> doctrine/doctrine-bundle ###
database:
image: postgres:${POSTGRES_VERSION:-16}-alpine
environment:
POSTGRES_DB: ${POSTGRES_DB:-app}
# You should definitely change the password in production
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!}
POSTGRES_USER: ${POSTGRES_USER:-app}
healthcheck:
test: ["CMD", "pg_isready", "-d", "${POSTGRES_DB:-app}", "-U", "${POSTGRES_USER:-app}"]
timeout: 5s
retries: 5
start_period: 60s
volumes:
- database_data:/var/lib/postgresql/data:rw
# You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
# - ./docker/db/data:/var/lib/postgresql/data:rw
###< doctrine/doctrine-bundle ###

volumes:
###> doctrine/doctrine-bundle ###
database_data:
###< doctrine/doctrine-bundle ###
116 changes: 116 additions & 0 deletions application/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"type": "project",
"license": "MIT",
"authors": [
{
"name": "Mathieu Santostefano",
"email": "[email protected]"
}
],
"minimum-stability": "beta",
"prefer-stable": true,
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/dbal": "^3",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^3.1",
"phpdocumentor/reflection-docblock": "^5.4",
"phpstan/phpdoc-parser": "^1.29",
"symfony/asset": "7.1.0-RC1",
"symfony/asset-mapper": "7.1.0-RC1",
"symfony/console": "7.1.0-RC1",
"symfony/doctrine-messenger": "7.1.0-RC1",
"symfony/dotenv": "7.1.0-RC1",
"symfony/expression-language": "7.1.0-RC1",
"symfony/flex": "^2",
"symfony/form": "7.1.0-RC1",
"symfony/framework-bundle": "7.1.0-RC1",
"symfony/http-client": "7.1.0-RC1",
"symfony/intl": "7.1.0-RC1",
"symfony/mailer": "7.1.0-RC1",
"symfony/mime": "7.1.0-RC1",
"symfony/monolog-bundle": "^3.0",
"symfony/notifier": "7.1.0-RC1",
"symfony/process": "7.1.0-RC1",
"symfony/property-access": "7.1.0-RC1",
"symfony/property-info": "7.1.0-RC1",
"symfony/resend-mailer": "7.1.*",
"symfony/runtime": "7.1.0-RC1",
"symfony/security-bundle": "7.1.0-RC1",
"symfony/serializer": "7.1.0-RC1",
"symfony/stimulus-bundle": "^2.17",
"symfony/string": "7.1.0-RC1",
"symfony/translation": "7.1.0-RC1",
"symfony/twig-bundle": "7.1.0-RC1",
"symfony/ux-turbo": "^2.17",
"symfony/validator": "7.1.0-RC1",
"symfony/web-link": "7.1.0-RC1",
"symfony/webhook": "7.1.*",
"symfony/yaml": "7.1.0-RC1",
"twig/extra-bundle": "^2.12|^3.0",
"twig/twig": "^2.12|^3.0"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"symfony/flex": true,
"symfony/runtime": true
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php73": "*",
"symfony/polyfill-php74": "*",
"symfony/polyfill-php80": "*",
"symfony/polyfill-php81": "*",
"symfony/polyfill-php82": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd",
"importmap:install": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "7.1.*"
}
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "7.1.0-RC1",
"symfony/css-selector": "7.1.0-RC1",
"symfony/debug-bundle": "7.1.0-RC1",
"symfony/maker-bundle": "^1.0",
"symfony/phpunit-bridge": "^7.0",
"symfony/stopwatch": "7.1.0-RC1",
"symfony/web-profiler-bundle": "7.1.0-RC1"
}
}
Loading