承接 markei/wordpress-smtp-configuration 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

markei/wordpress-smtp-configuration

Composer 安装命令:

composer require markei/wordpress-smtp-configuration

包简介

Configure WordPress for sending mail via SMTP mail supporting encryption, (basic) auth and xoauth2. Configuration is done via wp-config.php.

README 文档

README

Configure WordPress for sending mail via SMTP mail supporting encryption, (basic) auth and xoauth2. Configuration is done via wp-config.php.

For SMTP is supports plain connections but also SSL/TLS encryption (SMTPS) and STARTLS encryption. Authentication is possible via normal authentication (basic) and XOAUTH2. For XOAUTH2 authentification as a user (Authorization Code Flow) or service principal (Client Credential Flow) is possible. This makes it possible to mail via Gmail or Microsoft 365.

In the WordPress admin interface an e-mail test tool will become available to view the given configuration and let you sent a test mail.

This plugin is free, does not add signatures to your mail, no spam and no ad's.

How to

Activate the plugin in WordPress admin.

Add the next line to wordpress/wp-config.php above require_once(ABSPATH . 'wp-settings.php');

define('SMTP', 'smtp://localhost');

Supported options

The configuration supports a URL format. Example: protocol://host:port?optionA=valueA&optionB=valueB.

Protocol SMTP

Simple configuration, no auth, port 25

define('SMTP', 'smtp://localhost');

Simple configuration, no auth, with another port

define('SMTP', 'smtp://my-smtp-server:587');

With basic authentication, insecure because no encryption is set so username and password are send readable

define('SMTP', 'smtp://localhost:587?username=my-username&password=my-password');

Prefered way for authentification with STARTTLS encryption

define('SMTP', 'smtp://localhost:587?encryption=tls&username=my-username&password=my-password');

Prefered way for authentification with SMTPS encryption. Note encryption=ssl even the server uses a TLS protocol instead of and old-SSL protocol.

define('SMTP', 'smtp://localhost:465?encryption=ssl&username=my-username&password=my-password');
XOAUTH2 with client credentials (e.g. Microsoft 365)

Define client_id, client_secret, token_endpoint and scope as parameters. A access token is requested from the token_endpoint each time a mail is sent.

This is a good guide for setting up a service principal for SMTP mailing in Microsoft 365/Office 365/Outlook Online/Exchange Online. For 365 use server smtp.office365.com, port 587, token_endpoint=https://login.microsoftonline.com/<Directory (tenant ID)>/oauth2/v2.0/token and scope=https://outlook.office365.com/.default.

Caching can be enabled via the option cache=1, this will speed up the processes for sending mails becauses not for each mail a new token is requested. The access token is cached using the WordPress transient system.

define('SMTP', 'smtp://localhost:587?auth=xoauth2&client_id=my-client-id&client_secret=my-client-secret&token_endpoint=https://my-oauth-server/token&scope=sendmail&cache=1');

Example for Microsoft 365

define('SMTP', 'smtp://smtp.office365.com:587?auth=xoauth2&client_id=<Client ID>&client_secret=<Client Secret>&token_endpoint=https://login.microsoftonline.com/<Directory (tenant ID)>/oauth2/v2.0/token&scope=https://outlook.office365.com/.default&cache=1');
XOAUTH2 with authorization code flow (e.g. Gmail)

The plugin will use the following redirect_uri which much be configured in the Authorization server:

https://my-wordpress-website.tld/wp-content/plugins/smtp-configuration/oauth2-callback.php

Define client_id, client_secret, token_endpoint, auth_endpoint and scope as parameters. Extra parameters for the authorization server can be set via auth_endpoint_parameters which accepts an key-value array.

For Gmail use server smtp.gmail.com, port 587, token_endpoint=https://oauth2.googleapis.com/token, auth_endpoint=https://accounts.google.com/o/oauth2/auth, auth_endpoint_parameters[prompt]=consent&auth_endpoint_parameters[access_type]=offline and scope=https://mail.google.com/.

Caching can be enabled via the option cache=1, this will speed up the processes for sending mails becauses not for each mail the refresh token is rotated. The access token is cached using the WordPress transient system.

define('SMTP', 'smtp://smtp.gmail.com:587?auth=xoauth2&client_id=my-client-id&client_secret=my-client-secret&token_endpoint=https://my-oauth-server/token&scope=sendmail%20offline&auth_endpoint=https://my-oauth-server/auth&cache=1');

Example for Gmail (replace your client id and secret):

define('SMTP', 'smtp://smtp.gmail.com:587?auth=xoauth2&client_id=<Client ID>&client_secret=<Client Secret>&token_endpoint=https://oauth2.googleapis.com/token&scope=https://mail.google.com/&auth_endpoint=https://accounts.google.com/o/oauth2/auth&cache=1&auth_endpoint_parameters[prompt]=consent&auth_endpoint_parameters[access_type]=offline');

After configuration and enabling the plugin go to the SMTP configuration page in the Tools menu in the WordPress admin. Click on the Obtain token button.

Protocol Sendmail

No options are available.

define('SMTP', 'sendmail://');

Protocol mail

No options are available.

define('SMTP', 'mail://');

Debug

Add the option debug=1 to show debug information from PHPMailer. Don't enabled this in production it can contain secret information.

Install via composer

Install the plugin via Composer

composer require markei/wordpress-smtp-configuration

markei/wordpress-smtp-configuration 适用场景与选型建议

markei/wordpress-smtp-configuration 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 359 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 11 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「wordpress」 「smtp」 「wordpress-plugin」 「xoauth2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 markei/wordpress-smtp-configuration 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 markei/wordpress-smtp-configuration 我们能提供哪些服务?
定制开发 / 二次开发

基于 markei/wordpress-smtp-configuration 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 359
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-12