Download the PHP package 2am.tech/laravel-mail-api without Composer

On this page you can find all versions of the php package 2am.tech/laravel-mail-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-mail-api

Laravel Mail API

Build Codacy Badge Quality Codacy Badge Coverage

About Mail API Service

Laravel Mail API is an email microservice to avoid having to configure mail over and over on projects involving microservices infrastructure.

It uses Signed AppKeys to handle the authentications through requests. The mailer transport interface was build using Laravel Mail (powered by Symfony Mailer) with Markdown Mail Notifications to enhance the email layout configuration.

To accomplish dispatching emails with an efficient response time, Laravel Mail API uses Laravel Queues to execute the tasks in background. We already have configured a driver for Redis (Predis) connection. You are free to configure other driver if it's needed.

Finally, it makes use of Laravel Localization for content internationalization and Laravel Logs for logging.

Install

Configuration

Docker Container Configuration

A docker image was provided through Laravel Sail.

You can configure a shell alias for Sail command and make it easier to access.

Please, refer to Sail Docs to know more about executing commands in your application's container.

To start up/stop the docker container, use the following commands: To be able to use the docker container, you need to first install the dependencies. To achieve that, you must execute the given command:

If you're using Laravel Sail, refer to .env.sail for redis connection strings.

The .env.example file gives the basic structure your project must have in order to run the service properly. Copy its content to .env file.

Application Configuration

As mentioned before, we're using Signed AppKeys for requests authentication.

First, you have to define you're Access Token (AppKey and AppSecret) on ./config/laravel-mail-api, on AccessTokens section.

We already provided a sample access key.

You can register as many access token it's necessary for your microservices.

With the access token defined, we just need to sign it to and add its values to the request header.

Access Token Sign Algorithm

Define a hash algorithm to create a hashed token. The default is sha512. You can define it on by adding HASH_SIGNATURE on the .env file:

HASH_SIGNATURE=sha512

To create a signature for you access token, you follow this steps:

Get the current timestamp (on UTC) on ISO-8601 format.

Then, simple hash your AppKey with the gotten timestamp, using your AppSecret as the hash password.

A command was created to help the signature creation, for testing purposes:

Email Transport Configuration

You must configure your mailer transport on .env file as well. This project was built using SMTP. Laravel Mail provides an easy way to configure the driver your project needs.

This is a sample SMTP Driver configuration:

Usage

To serve the application, Laravel provides the handy built in command serve

This command serve your application at http://127.0.0.1:8000. If you run the command through Laravel Sail, the application will be served on port 80 instead http://127.0.0.1.

Endpoints

The API has one endpoint: /api/email/send.

A postman collection Laravel Mail API has been served to simplify the testing process.

/api/email/send

In order to have the authentication mechanism working, we must add the following headers:

Then you can send multipart/form-data request with the following parameters:

Here is a sample request:

Done. Now your new message is on the queue, ready to be dispatched. To achieve that, you just need to run this command:

Email Attachments

The /api/email/send endpoint apply validations for attachments mimetypes.

By default, the application will allow PDF and any Image mimetypes.

You can easily set an array of your needed mimetypes, or even set a string '*' to allow any mimetype. e.g. to allow any file mimetype, you just need to change this line on config/laravel-mail-api.php:

Customization

As mentioned before, this service uses Markdown Mail Notifications to enhance the email layout configuration. You can find the template files for Markdown published at resources/views/vendor/mail/html.

The email body is set on template files. It already has Laravel Localization to provide an internationalization feature to it.

You can check the default template at recources/views/templates/hello-world.blade.php and the password template at resruoces\views\templates\password.blade.php for reference, as they've been written with localization already.

You can define for how long a token will be valid by declaring the constant TOKEN_TIME (in minutes) in your .env file. Default is 60.

You can define the default email template declaring DEFAULT_TEMPLATE, where the default is hello-world and the default language by declaring the LANGUAGE constant (default en).

Deploying

Although the queue work command is handy and makes it really easy to consume the queue while testing the application, but it's extremely recommended to use Supervisor when deploying to production.

Laravel has a nice guide to properly configure the Supervisor.

Serverless deployment to AWS Lambda

This project uses Bref framework to empower a smoothly deployment to AWS Lambda.

It has a tiny list of dependencies to achieve that:

To install the Serverless framework:

Install Serverless plugin dependency:

And them, setup the AWS credentials for the Serverless framework:

You can change the project name on file serverless.yml to match your project name, right on the first line:

Last step before the actual deployment is to clear local cashed files:

and, them:

Once the process is finished, you will be prompted with the endpoint, functions and jobs created on AWS Lambda!

Contributing

Please, see CONTRIBUTING for details.

License

The BSD License (BSD). Please see License File for more information/

2am.tech

Web development has never been so fun!

https://2am.tech/


All versions of laravel-mail-api with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
bref/bref Version ^2.1
bref/laravel-bridge Version ^2.2
guzzlehttp/guzzle Version ^7.2
laravel/framework Version ^10.0
laravel/sanctum Version ^3.2
laravel/tinker Version ^2.8
predis/predis Version ^2.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package 2am.tech/laravel-mail-api contains the following files

Loading the files please wait ....