Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced laminas-mail with symfony/mailer #65

Merged
merged 9 commits into from
Nov 15, 2024
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
1 change: 0 additions & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
- ubuntu-latest

php:
- "8.1"
- "8.2"
- "8.3"

Expand Down
6 changes: 6 additions & 0 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ignore_php_platform_requirements": {
"8.4": true
},
"backwardCompatibilityCheck": true
}
43 changes: 12 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# dot-mail

> [!IMPORTANT]
> dot-mail is a wrapper on top of [laminas-mail](https://github.com/laminas/laminas-mail)
>
> ![Dynamic JSON Badge](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fapi.github.com%2Frepos%2Flaminas%2Flaminas-mail%2Fproperties%2Fvalues&query=%24%5B%3F(%40.property_name%3D%3D%22maintenance-mode%22)%5D.value&label=Maintenance%20Mode&color=%23d43442)
> dot-mail is a wrapper on top of [symfony mailer](https://github.com/symfony/mailer)

## dot-mail badges

![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-mail)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-mail/4.1.1)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-mail/5.0.0)

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-mail)](https://github.com/dotkernel/dot-mail/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-mail)](https://github.com/dotkernel/dot-mail/network)
Expand All @@ -18,7 +16,13 @@
[![Build Static](https://github.com/dotkernel/dot-mail/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-mail/actions/workflows/continuous-integration.yml)
[![codecov](https://codecov.io/gh/dotkernel/dot-mail/branch/4.0/graph/badge.svg?token=G51NEHYKD3)](https://codecov.io/gh/dotkernel/dot-mail)

[![SymfonyInsight](https://insight.symfony.com/projects/1995ea7c-3b34-4eee-ac48-3571860d0307/big.svg)](https://insight.symfony.com/projects/1995ea7c-3b34-4eee-ac48-3571860d0307)
## Installation

Install `dotkernel/dot-mail` by executing the following Composer command:

```shell
composer require dotkernel/dot-mail
```

## Configuration

Expand All @@ -32,7 +36,7 @@ return [
'dot_mail' => [
'default' => [
//...
'transport' => Laminas\Mail\Transport\Sendmail::class,
'transport' => Symfony\Component\Mailer\Transport\Smtp\SmtpTransport::class,
//...
]
]
Expand Down Expand Up @@ -61,7 +65,7 @@ return [
'dot_mail' => [
'default' => [
//...
'transport' => Laminas\Mail\Transport\Smtp::class,
'transport' => Symfony\Component\Mailer\Transport\Smtp\SmtpTransport::class,
'message_options' => [
'from' => '',
//...
Expand Down Expand Up @@ -137,7 +141,7 @@ if (! $result->isValid()) {
}
```

**Note : Invalid e-mail messages will not be sent.**
> Invalid e-mail messages will not be sent.

### Logging outgoing emails

Expand All @@ -161,26 +165,3 @@ return [
```

To disable it, set the value of `sent` to `null`.

### Saving a copy of an outgoing mail into a folder

### Valid only for SMTP Transport

First, make sure the `save_sent_message_folder` key is present in config file `mail.local.php` under `dot_mail.default`. Below you can see its placement and default value.

```php
<?php

return [
'dot_mail' => [
'default' => [
...
'save_sent_message_folder' => ['INBOX.Sent']
],
],
];
```

Common folder names are `INBOX`, `INBOX.Archive`, `INBOX.Drafts`, `INBOX.Sent`, `INBOX.Spam`, `INBOX.Trash`. If you have `MailService` available in your class, you can call `$this->mailService->getFolderGlobalNames()` to list the folder global names for the email you are using.

Multiple folders can be added to the `save_sent_message_folder` key to save a copy of the outgoing email in each folder.
3 changes: 2 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

| Version | Supported | PHP Version |
|---------|--------------------|----------------------------------------------------------------------------------------------------------|
| 4.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-mail/4.1.1) |
| 5.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-mail/5.0.0) |
| 4.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-mail/4.3.0) |
| <= 3.x | :x: | |


Expand Down
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{
"name": "dotkernel/dot-mail",
"type": "library",
"description": "DotKernel mail component based on laminas-mail",
"description": "Dotkernel mail component based on symfony mailer",
"license": "MIT",
"homepage": "https://github.com/dotkernel/dot-mail",
"keywords": [
"mail",
"services",
"laminas",
SergiuBota1 marked this conversation as resolved.
Show resolved Hide resolved
"laminas-mail",
"symfony",
"mailer",
"event",
"dot-event",
"laminas",
"laminas-dependency"
],
"authors": [
{
"name": "DotKernel Team",
"name": "Dotkernel Team",
"email": "[email protected]"
}
],
Expand All @@ -26,15 +27,15 @@
}
},
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"php": "~8.2.0 || ~8.3.0 || ~8.4.0",
"ext-fileinfo": "*",
"ext-json": "*",
"laminas/laminas-servicemanager": "^3.22",
"laminas/laminas-mail": "^2.25",
"dotkernel/dot-event": "^3.4"
"dotkernel/dot-event": "^3.4",
"symfony/mailer": "v7.1.6"
},
"require-dev": {
"laminas/laminas-coding-standard": "^2.5",
"laminas/laminas-coding-standard": "^3.0",
"mikey179/vfsstream": "^v1.6.11",
"phpunit/phpunit": "^10.5",
"vimeo/psalm": "^5.23"
Expand Down
26 changes: 6 additions & 20 deletions config/mail.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
return [

/**
* DotKernel mail module configuration
* Dotkernel mail module configuration
* Note that many of these options can be set programmatically too, when sending mail messages
* actually that is what you'll usually do, these config provide just default and options that remain the same for all mails
*/
Expand All @@ -16,18 +16,16 @@ return [

/**
* the mail transport to use
* can be any class implementing Laminas\Mail\Transport\TransportInterface
* can be any class implementing Symfony\Component\Mailer\Transport\TransportInterface
*
* for standard mail transports, you can use these aliases
* - sendmail => Laminas\Mail\Transport\Sendmail
* - smtp => Laminas\Mail\Transport\Smtp
* - file => Laminas\Mail\Transport\File
* - in_memory => Laminas\Mail\Transport\InMemory
* - sendmail => Symfony\Component\Mailer\Transport\SendmailTransport
* - smtp => Symfony\Component\Mailer\Transport\Smtp\SmtpTransport
*
* defaults to sendmail
**/

'transport' => \Laminas\Mail\Transport\Sendmail::class,
'transport' => Symfony\Component\Mailer\Transport\Smtp\SmtpTransport::class,

// Uncomment the below line if you want to save a copy of all sent emails to a certain IMAP folder
// Valid only if the Transport is SMTP
Expand Down Expand Up @@ -79,7 +77,7 @@ return [
],
],

//options that will be used only if Laminas\Mail\Transport\Smtp adapter is used
//options that will be used only if Symfony\Component\Mailer\Transport\Smtp\SmtpTransport adapter is used
'smtp_options' => [

//hostname or IP address of the mail server
Expand All @@ -106,18 +104,6 @@ return [
]
],

//file options that will be used only if the adapter is Laminas\Mail\Transport\File
/*'file_options' => [

//this is the folder where the file is going to be saved
//default value is 'data/mail/output'
'path' => 'data/mail/output',

//a callable that will get the Laminas\Mail\Transport\File object as an argument and should return the filename
//if null is used, and empty callable will be used
//'callback' => null,
],*/

//listeners to register with the mail service, for mail events
'event_listeners' => [
//[
Expand Down
1 change: 0 additions & 1 deletion docs/book/index.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/book/index.md
8 changes: 4 additions & 4 deletions docs/book/v4/configuration.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Configuration

Register `dot-mail` in you project by adding `Dot\Mail\ConfigProvider::class` to your configuration aggregator (to `config/config.php` for example).
After registering the `ConfigProvider` load the configuration file (`config/mail.global.php.dist`) by removing it's `.dist` extension and adding it to the `config/autoload` folder.
After registering the `ConfigProvider` copy the configuration file `config/mail.global.php.dist` into your project's `config/autoload/` directory as `mail.global.php`.

The resulting `mail.global.php` contains the necessary configurations for all available transport types, message options and logging options in one place. The config file provides a set of default values available to all mails under the `dot-mail.default` key.

Expand Down Expand Up @@ -30,12 +30,12 @@ The `dot_mail.default.save_sent_message_folder` key may be uncommented when usin

Using `Laminas\Mail\Transport\File` as the transport will require uncommenting the `dot-mail.default.file_options` key.

- Note: the configured path must be a writable directory
> The configured path must be a writable directory

```php
'file_options' => [
'path' => 'data/mail/output',
//'callback' => null,
'path' => 'data/mail/output',
//'callback' => null,
],
```

Expand Down
4 changes: 3 additions & 1 deletion docs/book/v4/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

Install `dotkernel/dot-mail` by executing the following Composer command:

composer require dotkernel/dot-mail
```shell
composer require dotkernel/dot-mail
```
2 changes: 0 additions & 2 deletions docs/book/v4/overview.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Overview

> dot-mail is a wrapper on top of [laminas-mail](https://github.com/laminas/laminas-mail)
>
> ![OSS Lifecycle](https://img.shields.io/osslifecycle/laminas/laminas-mail)

## Extra features

Expand Down
2 changes: 1 addition & 1 deletion docs/book/v4/transports.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- `Laminas\Mail\Transport\File`
- `Laminas\Mail\Transport\InMemory`

- Note: feel free to use any custom transport you desire, provided it implements the mentioned `TransportInterface`.
> Feel free to use any custom transport you desire, provided it implements the mentioned `TransportInterface`.

`Sendmail` is a wrapper over PHP's `mail()` function, and as such has a different behaviour on Windows than on *nix systems. Using sendmail on Windows **will not work in combination with** `addBcc()`.

Expand Down
2 changes: 1 addition & 1 deletion docs/book/v4/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if (! $result->isValid()) {
}
```

**Note : Invalid e-mail messages will not be sent.**
> Invalid e-mail messages will not be sent.

## Logging outgoing emails

Expand Down
55 changes: 55 additions & 0 deletions docs/book/v5/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Configuration

Register `dot-mail` in you project by adding `Dot\Mail\ConfigProvider::class` to your configuration aggregator (to `config/config.php` for example).
After registering the `ConfigProvider` copy the configuration file `config/mail.global.php.dist` into your project's `config/autoload/` directory as `mail.global.php`.

The resulting `mail.global.php` contains the necessary configurations for all available transport types, message options and logging options in one place. The config file provides a set of default values available to all mails under the `dot-mail.default` key.

Many of these options can be programmatically set when sending the actual email.

An example of this is the `dot-mail.default.message_options` key, which can be filled in with default message values to be available to all emails.
When sending the actual email, these values can be overwritten by using an available "setter" function, supplemented by using "add" functions or simply left as the default.

```php
// setter will overwrite existing destination email
$this->mailService->getMessage()->setTo("[email protected]");

// existing destination email kept, new destination email added alongside it
$this->mailService->getMessage()->addTo("[email protected]");
```

## Transport configuration

`dot-mail` uses the `transport` key under the main `dot_mail` configuration key to select the email transport.
It has four email transport classes available by default (`SmtpTransport`), one of which is to be added under the `dot_mail.transport` key for use.

Sending email with the `Smtp` transport requires valid data for the values under `dot-mail.default.smtp_options`, which is only used in this case.

> The configured path must be a writable directory

```php
'file_options' => [
'path' => 'data/mail/output',
//'callback' => null,
],
```

## Logging configuration

Uncommenting the `dot-mail.log` key will save a copy of all sent emails' subject, recipient addresses, cc and bcc addresses alongside a timestamp.
In order to enable it, make sure that your `mail.local.php` has the below `log` configuration under the `dot_mail` key:

```php
<?php

return [
'dot_mail' => [
...
'log' => [
'sent' => getcwd() . '/log/mail/sent.log'
]
]
];
```

To disable it, set the value of `sent` to `null`.
7 changes: 7 additions & 0 deletions docs/book/v5/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Installation

Install `dotkernel/dot-mail` by executing the following Composer command:

```shell
composer require dotkernel/dot-mail
```
7 changes: 7 additions & 0 deletions docs/book/v5/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Overview

> dot-mail is a wrapper on top of [symfony mailer](https://github.com/symfony/mailer)

## Extra features

- the option to log the results of the mailing process it provides the developer with more information and greater control.
14 changes: 14 additions & 0 deletions docs/book/v5/transports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Transports

`dot-mail` can use any transport class that implements `Symfony\Component\Mailer\Transport\TransportInterface`, with the standard transport available being:

- `Symfony\Component\Mailer\Transport\Smtp\SmtpTransport,`
- `Symfony\Component\Mailer\Transport\SendmailTransport,`

> Feel free to use any custom transport you desire, provided it implements the mentioned `TransportInterface`.

`Sendmail` is a wrapper over PHP's `mail()` function, and as such has a different behaviour on Windows than on *nix systems. Using sendmail on Windows **will not work in combination with** `addBcc()`.

- Note: emails sent using the sendmail transport will be more often delivered to SPAM.

`Smtp` connects to the configured SMTP host in order to handle sending emails.
Loading