胖蒜

分享有价值的资源

Typecho 使用 Mailer 插件的相关设置及模版美化

Typecho 的轻量导致某些基础设施缺失,邮件通知就是其中一项。这些年来无数人写了无数的邮件通知插件,其中许多要不是极度臃肿,要不就是年久失修了。
本插件需要使用 Typecho 开发版(17.11.15 以上版本)。插件支持自定义模板。使用 Typecho 最新的异步回调机制编写,基于 Joyqi 给出的 Demo。

使用方法

下载插件,上传至插件目录,后台启用后设置相关信息。然后在博客评论区 form 元素中合适位置添加:

<span>
  <input name="receiveMail" type="checkbox" value="yes" checked />
  <label for="receiveMail"><strong>接收</strong>邮件通知</label>
</span>

以上代码必须添加,不添加不会发信。

插件设置

在插件设置页面填写发件信息。注意,如果你是用的 QQ 之类的邮箱,可能需要生成专用密码,而不能直接使用登陆密码。
插件设置

发信规则

发信规则
也可以单独设置是否提醒博主或者访客。待审或垃圾评论不会提醒访客。

模版美化

  1. 博主发信内容模板 (templateHost.html)
<div style="width: 550px;height: auto;border-radius: 5px;margin:0 auto;border:1px solid #ffb0b0;box-shadow: 0px 0px 20px #888888;position: relative;">
    <div style="background-image: url(https://wx4.sinaimg.cn/mw1024/c5095e03gy1gaibg9o3zrj20hx0btwi1.jpg);width:550px;height: 300px;background-size: cover;background-repeat: no-repeat;border-radius: 5px 5px 0px 0px;"></div>
    <div style="background-color:white;line-height:180%;padding:0 15px 12px;width:520px;margin:10px auto;color:#555555;font-family:'Century Gothic','Trebuchet MS','Hiragino Sans GB',微软雅黑,'Microsoft Yahei',Tahoma,Helvetica,Arial,'SimSun',sans-serif;font-size:12px;margin-bottom: 0px;">
        <h2 style="border-bottom:1px solid #DDD;font-size:14px;font-weight:normal;padding:13px 0 10px 8px;"><span style="color: #12ADDB;font-weight: bold;">&gt; </span>您的文章<a style="text-decoration:none;color: #12ADDB;" href="{{post_permalink}}" target="_blank">《{{post_title}}》</a>有了新的评论耶~</h2>
        <div style="padding:0 12px 0 12px;margin-top:18px">
            <p><strong>{{comment_author_name}}</strong>&nbsp;给您的评论:</p>
            <p style="background-color: #f5f5f5;border: 0px solid #DDD;padding: 10px 15px;margin:18px 0">{{comment_content}}</p>
            <p>其他信息:</p>
            <p style="background-color: #f5f5f5;border: 0px solid #DDD;padding: 10px 15px;margin:18px 0">IP:{{ip}}<br />邮箱:<a href="mailto:{{comment_author_mail}}">{{comment_author_mail}}</a><br />状态:{{status}} [<a href='{{manage_url}}' target='_blank'>管理评论</a>]</p>
        </div>
    </div>
    <a style="text-decoration: none;color: rgb(255, 255, 255);width: 40%;text-align: center;background-color: rgb(255, 114, 114);height: 40px;line-height: 40px;box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.3);display: block;margin: auto;" href="{{comment_permalink}}" target="_blank">查看回复的完整內容</a>
    <div style="color:#8c8c8c;;font-family: 'Century Gothic','Trebuchet MS','Hiragino Sans GB',微软雅黑,'Microsoft Yahei',Tahoma,Helvetica,Arial,'SimSun',sans-serif;font-size: 10px;width: 100%;text-align: center;">
        <p>©2020 Copyright <a style="text-decoration: none;" target="_blank" href="{{site_url}}">{{site_name}}</a></p>
    </div>
</div>
  1. 向访客发信内容模板 (templateGuest.html)
<div style="width: 550px;height: auto;border-radius: 5px;margin:0 auto;border:1px solid #ffb0b0;box-shadow: 0px 0px 20px #888888;position: relative;padding-bottom: 5px;">
    <div style="background-image: url(https://wx4.sinaimg.cn/mw1024/c5095e03gy1gaibg9o3zrj20hx0btwi1.jpg);width:550px;height: 350px;background-size: cover;background-repeat: no-repeat;border-radius: 5px 5px 0px 0px;"></div>
    <div style="width: 200px;height: 40px;background-color: rgb(255, 114, 114);margin-top: -20px;margin-left: 20px;box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.3);color: rgb(255, 255, 255);text-align: center;line-height: 40px;">Dear: {{comment_author_name}}</div>
    <div style="background-color:white;line-height:180%;padding:0 15px 12px;width:520px;margin:30px auto;color:#555555;font-family:'Century Gothic','Trebuchet MS','Hiragino Sans GB',微软雅黑,'Microsoft Yahei',Tahoma,Helvetica,Arial,'SimSun',sans-serif;font-size:12px;margin-bottom: 0px;">
        <h2 style="border-bottom:1px solid #DDD;font-size:14px;font-weight:normal;padding:13px 0 10px 8px;"><span style="color: #12ADDB;font-weight: bold;">&gt; </span>您在<a style="text-decoration:none;color: #12ADDB;" href="{{post_permalink}}" target="_blank">《{{post_title}}》</a>的评论有了新的回复呐~</h2>
        <div style="padding:0 12px 0 12px;margin-top:18px">
            <p>您的评论:</p>
            <p style="background-color: #f5f5f5;border: 0px solid #DDD;padding: 10px 15px;margin:18px 0">{{comment_parent_content}}</p>
            <p><strong>{{comment_author_name}}</strong>&nbsp;给您的回复:</p>
            <p style="background-color: #f5f5f5;border: 0px solid #DDD;padding: 10px 15px;margin:18px 0">{{comment_content}}</p>
        </div>
    </div>
    <div style="color:#8c8c8c;;font-family: 'Century Gothic','Trebuchet MS','Hiragino Sans GB',微软雅黑,'Microsoft Yahei',Tahoma,Helvetica,Arial,'SimSun',sans-serif;font-size: 10px;width: 100%;text-align: center;word-wrap:break-word;margin-top: -30px;">
        <p style="padding:20px;"></p>
    </div>
    <a style="text-decoration: none;color: rgb(255, 255, 255);width: 40%;text-align: center;background-color: rgb(255, 114, 114);height: 40px;line-height: 40px;box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.3);display: block;margin: auto;" href="{{comment_permalink}}" target="_blank">查看回复的完整內容</a>
    <div style="color:#8c8c8c;;font-family: 'Century Gothic','Trebuchet MS','Hiragino Sans GB',微软雅黑,'Microsoft Yahei',Tahoma,Helvetica,Arial,'SimSun',sans-serif;font-size: 10px;width: 100%;text-align: center;margin-top: 30px;">
        <p>本邮件为系统自动发送,请勿直接回复。</p>
    </div>
    <div style="color:#8c8c8c;;font-family: 'Century Gothic','Trebuchet MS','Hiragino Sans GB',微软雅黑,'Microsoft Yahei',Tahoma,Helvetica,Arial,'SimSun',sans-serif;font-size: 10px;width: 100%;text-align: center;">
        <p style="color: #e9e9e9">本邮件为系统自动发送。欢迎再次访问<a style="text-decoration: none;" target="_blank" href="{{site_url}}">{{site_name}}</a>。</p>
    </div>
</div>

下载地址

https://github.com/AlanDecode/Typecho-Plugin-Mailer

参考页面

https://blog.imalan.cn/archives/349/
https://blog.irain.in/archives/typecho_mailer.html
https://github.com/AlanDecode/Typecho-Plugin-Mailer

感觉很棒,欢迎点赞 OR 打赏~

分享到:

评论 (3)

立即登录评论
可联系QQ744272645咨询

    请问,我插件设置没问题,为什么保存设置后出现连接邮箱服务器失败?

      检查一下插件的设置,另外看看服务器对应的端口开了没有?邮箱提供商里面的设置是否正确。

        端口问题。感谢!

马上咨询 自媒体号