Giter VIP home page Giter VIP logo

slmmail's Introduction

SlmMail

Build Status Latest Stable Version Scrutinizer Code Quality

SlmMail is a module that integrates with various third-parties API to send mails. Integration is provided with the API of those services. It does not handle SMTP.

Here are the currently supported services:

Installation

  1. First install the repo:

    composer require slm/mail

    • For Laminas MVC add SlmMail in your application.config.php file.
    • For Mezzio it should prompt whether we want to autoconfigure. Accept this.
  2. In order to use a mail service, you now need to configure it. We have provided a sample configuration file per mail server.

    Copy the sample configuration file to your autoload directory. For example for Mandrill one would use

    cp vendor/slm/mail/config/slm_mail.mandrill.local.php.dist config/autoload/slm_mail.mandrill.local.php

    Please tweak the dummy contents in this file. This file will contain the credentials.

Usage

One can now fetch the dependencies from the service manager. And now compose a message:

$message = new \Laminas\Mail\Message();
$message
    ->setTo('send@to')
    ->setFrom('send@by')
    ->setSubject('Subject')
    ->setBody('Contents');

$mandrillService = $container->get(\SlmMail\Service\MandrillService::class);
$mandrillService->send($message);

Documentation

Documentation for SlmMail is splitted for each provider:

Cook-book

How to send an HTML email ?

Every email providers used in SlmMail allow to send HTML emails. However, by default, if you set the mail's content using the setBody content, this content will be considered as the plain text version as shown below:

$message = new \Laminas\Mail\Message();

// This will be considered as plain text message, even if the string is valid HTML code
$message->setBody('Hello world');

To send a HTML version, you must specify the body as a MimeMessage, and add the HTML version as a MIME part, as shown below:

$message = new \Laminas\Mail\Message();

$htmlPart = new \Laminas\Mime\Part('<html><body><h1>Hello world</h1></body></html>');
$htmlPart->type = "text/html";

$textPart = new \Laminas\Mime\Part('Hello world');
$textPart->type = "text/plain";

$body = new \Laminas\Mime\Message();
$body->setParts(array($textPart, $htmlPart));

$message->setBody($body);

For accessibility purposes, you should always provide both a text and HTML version of your mails.

multipart/alternative emails with attachments

The correct way to compose an email message that contains text, html and attachments is to create a multipart/alternative part containing the text and html parts, followed by one or more parts for the attachments. See the Laminas Documentation for a full example.

How to configure HttpClient with http_options and http_adapter

By default the adapter is Laminas\Http\Client\Adapter\Socket but you can override it with other adapter like this in your slm_mail.*.local.php

'slm_mail' => array(
    // Here your email service provider options

    'http_adapter' => 'Laminas\Http\Client\Adapter\Proxy' // for example
)

If you want to change some options of your adapter please refer to you adapter class in var $config here and override these in your slm_mail.*.local.php like this :

'slm_mail' => array(
    // Here your email service provider options

    // example for Socket adapter
    'http_options' => array(
        'sslverifypeer' => false,
        'persistent' => true,
    ),
)

Which provider should I choose?

We won't answer you :-)! Each provider has their own set of features. You should carefully read each website to discover which one suits your needs best.

Who to thank?

Jurian Sluiman and Michaël Gallego did the initial work on creating this repo, and maintained it for a long time.

Currently it is maintained by:

slmmail's People

Contributors

bakura10 avatar basz avatar christaggart avatar danielss89 avatar dorongutman avatar erik-maas avatar imonteiro avatar jackdpeterson avatar juriansluiman avatar koenkivits avatar localheinz avatar mariojrrc avatar mrvralex avatar nickvanderveeken avatar nikraz avatar ojhaujjwal avatar orkin avatar rcapile avatar roelvanduijnhoven avatar sb8244 avatar shauno avatar shevron avatar snapshotpl avatar tdclaritum 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slmmail's Issues

Allow to make send requests asynchronously

It's easy with Guzzle as it has an AsyncPlugin, but apparently CURL has a support for that, so it may be interesting to allow each send method in services to send asyncrhonously.

[Idea] Allow for use of viewmodels and layouts

It would be cool if you could use ViewModels as 'messages'. So if i wanted to send an email i could do

$viewModel = new ViewModel(array('my' => 'data));
$mailService->send($viewModel);

Even better if you could set a layout in config which would be automatically applied to the viewmodel.

Would this make sense to have in SlmMail or would you rather have another module for it?

Return Postmark API response

I just sent a few first messages with the Postmark service and it works. I'm a bit disapointed that the transport::send() method doesn't return the API response.

The Postmark API responds like this:

{
  "ErrorCode" : 0,
  "Message" : "OK",
  "MessageID" : "b7bc2f4a-e38e-4336-af7d-e6c392c2f817",
  "SubmittedAt" : "2010-11-26T12:01:05.1794748-05:00",
  "To" : "[email protected]"
}

The MessageID is very helpful for direct bounce tracking. Is there a reason why you don't preserve the API response?

Asynchronous API

With the evolution of react, it's time now to think about creating asynchronous API.

$transport->send($message)
    ->then(
        function() {
            // message is sent, lets rock the world
        },
        function(\Exception $e) {
           // error sending message
        }
    );

Extending SES to support setTemplate and passing data to the template.

Hi,
My primary usage for the mail is using AWS SES . While this module supports that, but I don't see anywhere to set a template for the same. I am not sure how to do this.
Would be great if someone could outline how to extend it so that it will support setTemplate and passing data to the template page .
It would be great if the module starts supporting sendy.

Install SlmMail with zf2 dev-develop

This is my composer.json file

{
"name": "test site",
"description": "test site",
"license": "BSD-3-Clause",
"minimum-stability": "dev",
"repositories": [
{
"type": "composer",
"url": "https://packages.zendframework.com/"
}
],
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "dev-develop",
"zfcampus/zf-apigility": "dev-master",
"doctrine/doctrine-orm-module":"0.",
"doctrine/common": "2.3.0",
"silvester/reverse-oauth2": "dev-master",
"FortAwesome/Font-Awesome": "
",
"aws/aws-sdk-php-zf2": "1.0.",
"codeception/codeception": "1.8.
",
"neilime/zf2-assets-bundle": "dev-master",
"ocramius/ocra-service-manager": "dev-master"
},
"require-dev": {
"zendframework/zftool": "dev-master",
"zendframework/zend-developer-tools": "dev-master"
}
}

I need to install the SlmMail package but it give lot of dependency errors. How can I install SlmMail package with above configs.

get was unable to fetch or create an instance for getServiceLocator

I am trying to install the SlmMail using instructions given on github. I made a file in my registration module and added html email to it . It cannot find the service locator

Zend\View\HelperPluginManager::get was unable to fetch or create an instance for getServiceLocator

Enhance documentation

At this moment, documentation on the README is quite long and in the docs/ folder there is only documentation about all specific providers. We can ease the first step of SlmMail usage.

  • Provide clear description of SlmMail in introduction
  • Add links to the various services in introduction again
  • Shorten installation instructions
  • Offload pricing to docs/ folder
  • Add small list how to get the transport from SM
  • Remove TODO section (creates issues)
  • Add Development section where it is stated all api calls are not unit tested, so every user must test their api usage before going into production
  • Add CHANGELOG.md

Tag a release

Could anyone tag a release? The latest one is from May 2017 and it would be great to be able to use the Laminas version of SlmMail. Thanks!

Services sending HTML and text incorrectly

Each of the services' sendMessage() methods has a section like this:

$params = array(
    'subject'  => $message->getSubject(),
    'html'     => $message->getBody(),
    'text'     => $message->getBodyText(),
);

There is a bug here and and it's root is a misunderstanding of getBody() and getBodyText().

The difference between these two methods is that the former returns an object and the latter a string (the contents of the object). Unlike ZF1, the message doesn't include the fields for HTML and text: they are objects of type \Zend\Mime\Message.

Most services allow for sending HTML and/or text, so the service should support that aswell.

The code should check the 'content-type' of each mime part in the message body and decide whether it's HTML or text. Then send only the types that exist to the server.

Am I missing anything?

ElasticEmail error when unauthorized

Currently, without using this library I get a "Unauthorized: Dashboard" message when my credentials are not right.

Using the ElasticMailService it should throws an Exception.The code flow on \SlmMail\Service\ElasticMailService.php line 331 is not catching this message because it is wrongly comparing the result.

See:
if ($result !== 'Unauthorized: ') {
return $result;
}

I gonna create a PR to fix that.

Thanks.

Zend 2 app + SendGrid emails sent are blocked by Gmail

I'm integrating SendGrid with Zend app and it works for all regular addresses except for gmail. 👎
SendGrid says it's not hitting their servers so not sure what is going on. Any help will be greatly appreciated.
The Zend 2 code I'm using is (obviously not posting the user and pass)


$smtpServer = 'smtp.sendgrid.net';
$message = new Mail\Message();
$message->addTo($to)
->addFrom('[email protected]')
->setSubject($subject)
->setBody($body);
// Setup SMTP transport using LOGIN authentication
$transport = new SmtpTransport();
$options = new SmtpOptions(array(
'name' => $smtpServer,
'host' => $smtpServer, //'127.0.0.1',
'port' => 25, // Notice port change for TLS is 587
'connection_class' => 'plain',
'connection_config' => array(
'username' => $username,
'password' => $password,
//'ssl' => 'tls',
),
));
$transport->setOptions($options);
$transport->send($message);


Here is the failed header when trying to send test message to SendGrid.

This message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

[email protected]
host alt4.gmail-smtp-in.l.google.com [74.125.24.27]
SMTP error from remote mail server after end of data:
550-5.7.1 [70.32.72.15 5] Our system has detected that this message is
550-5.7.1 likely unsolicited mail. To reduce the amount of spam sent to Gmail,
550-5.7.1 this message has been blocked. Please visit
550 5.7.1 https://support.google.com/mail/answer/188131 for more information. 4si2564792wmb.92 - gsmtp
Reporting-MTA: dns; zsfs-bp7g.accessdomain.com

Action: failed
Final-Recipient: rfc822;[email protected]
Status: 5.0.0
Remote-MTA: dns; alt4.gmail-smtp-in.l.google.com
Diagnostic-Code: smtp; 550-5.7.1 [70.32.72.15 5] Our system has detected that this message is
550-5.7.1 likely unsolicited mail. To reduce the amount of spam sent to Gmail,
550-5.7.1 this message has been blocked. Please visit
550 5.7.1 https://support.google.com/mail/answer/188131 for more information. 4si2564792wmb.92 - gsmtp
From: [email protected]
Subject: Your new password!
Date: February 24, 2016 at 11:36:52 PM PST
To: [email protected]


Here is the failure report:
Event: failure error
Sender User: danceraccess
Sender Domain: danceraccess.com
Sender: [email protected]
Sent Time: Feb 24, 2016 11:36:23 PM
Sender Host: smtp.sendgrid.net
Sender IP: 127.0.0.1
Authentication: dovecot_plain
Spam Score: 0
Recipient: [email protected]
Delivered To:
Delivery User:
Delivery Domain:
Router: dkim_lookuphost
Transport: dkim_remote_smtp
Out Time: Feb 24, 2016 11:37:23 PM
ID: 1aYqTk-00086I-EK
Delivery Host: alt4.gmail-smtp-in.l.google.com
Delivery IP: 74.125.24.27
Size: 5.94 KB
Result: ECDHE-RSA-AES128-GCM-SHA256:128 CV=yes: SMTP error from remote mail server after end of data: 550-5.7.1 [70.32.72.15 5] Our system has detected that this message is\n550-5.7.1 likely unsolicited mail. To reduce the amount of spam sent to Gmail


Please help!!!

Refactor

Hi Jurians,

I just finished school and I'll be completely free for 2 weeks, therefore I'll work mostly on OSS projects those two weeks. I think SlmMail is a good module as this really simplify a lot of things.

As for SlmQueue, I'll first clean the module to latest best practices. As we have a lot more adapters than for SlmQueue, I don't think it's a good idea to "split" the module into a lot of smaller modules. Therefore, for Amazon SES the simplest is to use the new SDK (well, we could do it manually of course by preparing the headers, but I find it harder and more error-prone), so I think we can instead add "suggestion" in composer.json, so that people not using SES does not download the whole SDK for nothing.

Do you have any wishes for this module ? I'll need help as I don't use most of those services...

For instance, it looks like the module does not offer any way to write e-mails using templates and Zend\View. I think this should be added no?

Default adapter

Hi,

When using SlmMail on my EC2 server this morning, I realized that most mails didn't work today because of CA cert issue. It appears that I had to use the Curl adapter instead or change option for the Socket adapter.

Should we assume to change the options by default too?

SSLv3 failure at Mandrill

Using SLMMail for Mandrill integration.

I'm getting the SSLv3 error, every time I'm trying to use Mandrill service:

stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure

I did try to write the list of ciphers into /mods_available/ssl.conf but seems like this has no effect
I've also found this blog article http://blog.mandrill.com/poodle-sslv3-update.html that states SSLv3 was disabled by Mandrill.
So given I've tried removing it from ssl.conf I have no idea why it keeps using it at SLMMail.
P.S. trying curl -v https://mandrillapp.com results with an OK connection using SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384

PHP Version

The last version of ZendMail requires the php version greater than 5.5 and less than 7.0.
The version 2.5.0 require PHP greater than 5.3.23.

The problem is a that as of PHP 5.4 you can also use the short array syntax, which replaces array() with []. That change broke the test with PHP 5.3.

In HeaderValue validation is used short array syntax.

https://github.com/zendframework/zend-mail/blob/master/src/Header/HeaderValue.php#L90
https://github.com/zendframework/zend-mail/blob/release-2.7.1/composer.json#L16
https://github.com/zendframework/zend-mail/blob/release-2.5.0/composer.json#L16
https://github.com/juriansluiman/SlmMail/blob/master/composer.json#L33

Issue with SendGrid Error Response

The following is done on the result of the sendgrid api:
$result = json_decode($response->getBody(), true);

This means that an array will be returned and not an object. However, in the error checking bit, the $result is treated as an object:
if (isset($result->errors) && is_array($result->errors)) {

The true needs to be removed or the ->errors need to be referenced as an array.

Unable to enable crypto on TCP connection api.mailgun.net

Hello,

When trying to send the mail with the GunMail API, the follow error occurred:

"Unable to enable crypto on TCP connection api.mailgun.net: make sure the "sslcafile" or "sslcapath" option are properly set for the environment."

Also there seems to be a v3 version of the API. API_ENDPOINT is configured as v2.

Thank you in advance!

SES - Enhancement request: switch to latest Aws ZF2 module

It appears that this is presently undocumented so I'll at least list this as an issue. This module depends on the older version of the AWS ZF2 module and not on the latest version.

Converting to a newer version looks to be as simple as modifying SesServiceFactory to:

namespace SlmMail\Factory;

use SlmMail\Service\SesService;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Aws\Sdk;

class SesServiceFactory implements FactoryInterface
{

    /**
     *
     * {@inheritDoc}
     *
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        return new SesService($serviceLocator->get(Sdk::class)->createSes());
    }
}

Is this something that is planned in the near future? I realize that this may also affect other modules like SlmQueue and should probably be committed in parallel for projects that depends on both SlmQueue as well as SlmMail.

[BLOCKER] Fix AlphaMail

Hi,

There was a problem with the send mail for AlphaMail service. I contacted them, they have recently changed their API to v2. Send mails seem to work now, but not other methods.

I'm investigating the problem with them, so please do not tag v1.0 final before this get fixed :).

SendGrid Attachments

I have been using this module with SendGrid and just started sending attachments. Oddly, my excel files were "corrupted" and easily fixed by excel, but the byte size did not match what I sent it (~100 bytes more).

I dug into the SendGridService and see this line:

$post->set('files[' . $attachment->filename . ']', $attachment->getRawContent() . ';type=' . $attachment->type);

However, this is not correct as the type is being appended to the end of the file. Removing this fixed my corruption issue. I recommend removing this line from production because ";type=whatever" is not a standard file protocol. I don't mind doing this and pull requesting.

Line should be:

$post->set('files[' . $attachment->filename . ']', $attachment->getRawContent());

PHP 5.3 end of live

Hi

This package looks good, we're most probably going to use it for our PostMark integration. The one thing that strikes me at first sight is the PHP 5.3 requirement, do you mean PHP 5.3+ is it tested on PHP 5.5 and 5.6?

Cheers
Markus

Missing method in bounce API

I just found this post http://blog.postmarkapp.com/tagged/bounce which is from 2012 and introduces the possibility to query the bounce API directly via messageID. I find this very helpful but it seems the guys at Postmark forgot to document the behaviour in their API docs. As you probably followed the documentation this feature is also missing in your library, if I'm not blind or confused. :)

Update file phpdoc with license

All files must have a phpdoc with license

  • Add missing phpdoc blocks with license information
  • Remove @package line in existing license info
  • Replace 2012 by 2012-2013 in existing license info

Mailgun: support templates

Hello,

I use Mandrill for months, but since it's not free anymore, I'm going to use Mailgun.
I saw there is a template feature in Mailgun, but nothing in the SlmMail Mailgun support.

Is it a missing feature ? Or I'm missing something ?

Thanks for your awesome work !

Cannot install project via composer

Sorry if I'm doing anything wrong but I just copied your configs to my repo and it gave me an error :

[UnexpectedValueException]
Could not parse version constraint >=1.: Invalid version string "1."

I removed the 1.* but error still persisted.

Can you tell me what am I doing wrong? thanks

Search API for Mandrill

Hello,
I was wondering if adding a search method to the Mandrill Service would be considered in-scope for this package. There is already integration utilizing the search.json endpoint, but nothing exposes it directly (as far as I can tell).

Postage: add support for recipient variables

While doing a quick overview of what's new in all the API we support, I realized that Postage support variables per recipient. We only support global variables. (Reference: http://help.postageapp.com/kb/api/send_message)

I suggest:

  • Renaming getVariables to getGlobalVariables (as in Mandrill, and because it makes sense)
  • Adding a getVariables which take recipient address as first parameter (as in Mandrill).

As this is a BC, we may do it for 2.0 (I don't think it's a big deal to iterate quickly, as SlmMail is really working well, I see no problem at quickly having another major version for such things).

Companies using SlmMail

I'm interested to know how many companies are actually using SlmMail for their company. Feel free to drop a comment below with a link to your product. I'll update the issue with these responses.

  • Webador, a DIY website builder.
  • Research Square, a preprint platform and an academic author services company.
  • Bright Answer, part of tool that builds custom online research and psychometrics solutions.
  • Tiki24 to let their customers send mail using different adapters.

Release 3.0

I want to release a new version quickly that ships the latest work.

I released v3.0-alpha as a test-bed. Would love to hear feedback before I actually release it!

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.