Ghost 开源博客平台

Ghost 是一个简洁、强大的写作平台。你只须专注于用文字表达你的想法就好,其余的事情就让 Ghost 来帮你处理吧。

Ghost 邮件系统设置详解

以下文档详细讲解了如何配置 Ghost 的邮件功能。Ghost 底层依赖 Nodemailer,其文档提供了实例参考。

还在等什么?

其他大部分博客系统基本上都是用 PHP 开发的。如果你以前使用过类似系统,你可能已经习惯了系统为你自动配置好邮件功能。但是,Ghost 是基于 Node.js 平台开发的,Node 还很新,还有很多不成熟的地方。这就需要你自己花点儿力气将邮件配置好。

不过不用害怕,设置邮件这件差事一般只需要做一次。我们接下来一步步教你如何设置。

为何需要邮件

目前,Ghost 系统中用到邮件功能的地方只有在你找回密码的时候。虽然用处有限,但是当你遇到这个问题的时候他会对你很有用的。

将来,Ghost 还将支持设置基于邮件的博客订阅功能。还有通过邮件发送用户详细资料等其他可以利用邮件完成的一些特色功能。

如何配置?

首先你需要在邮件服务商处有一个账号。我们强烈推荐 Mailgun。他们提供了免费的初级账号,可以发的邮件数比其他邮件服务商的多。你还可以使用 Gmail 或 Amazon SES。

一旦你决定了使用哪家邮件服务商,你就把配置信息填写到 Ghost 的配置文件中即可。不管你将 Ghost 安装到哪里,都可以在根目录找到 config.js 文件。如果没有 config.js 文件,可以复制 config.example.js 并重名为 config.js

Mailgun

Head along to mailgun.com and sign up for an account. It’s free to use up to 10.000 emails per month. After signing up with Mailgun, verify your email address and log-in to your account. Mailgun allows you to use your own domain for sending transactional emails but if you do not own one it is possible to simply use the handy subdomain that they provide you with (also known as the sandbox domain), although sandbox domains are limited to 300 emails per day. You can change this later, so for now let’s use the subdomain automatically generated for you.

Now you have two choices:

  1. Use the official Mailgun config.js generator available here
  2. Edit your files manually (Continue reading below)

You’re going to need to find your new email service username and password that Mailgun have created for you (they’re not the ones you sign up with), by clicking on your sandbox domain on the right hand side. Here is an updated screencast to understand exactly where to find these details:

Right, now you’ve got everything you need, it’s time to open up your config file. Open your config.js file in the editor of your choice. Navigate to the environment you want to setup mail for, and change your mail settings to look like this:

mail: {  
transport: 'SMTP',  
    options: {
        service: 'Mailgun',
        auth: {
            user: '',
            pass: ''
        }
    }
}

Put your ‘Login’ from mailgun between the quote marks next to ‘user’ and your ‘Password’ from mailgun inside the quotes next to ‘pass’. If I was configuring mailgun for the ‘tryghosttest’ account, it would look like this:

mail: {  
    transport: 'SMTP',
    options: {
        service: 'Mailgun',
        auth: {
            user: 'postmaster@tryghosttest.mailgun.org',
            pass: '25ip4bzyjwo1'
        }
    }
}

Keep an eye out for all of the colons, quotes and curly brackets. Misplace one of those and you’ll find you get weird errors.

You can reuse your settings for both your development and production environment if you have both.

Amazon SES

You can sign up for an Amazon Simple Email Service account over at http://aws.amazon.com/ses/. Once you finish signing up, you’ll be given an SMTP user name and password.

Open Ghost’s config.js file in the editor of your choice. Navigate to the environment you want to setup mail for, and add your Amazon SMTP credentials to your mail settings as shown below:

mail: {  
    transport: 'SMTP',
    host: 'YOU-SES-SERVER-NAME',
        options: {
            port: 465,
            service: 'SES',
            auth: {
                user: 'YOUR-SES-ACCESS-KEY-ID',
                pass: 'YOUR-SES-SECRET-ACCESS-KEY'
            }
        }
}

Another way to configure mail is using your AWS access keys, like this:

mail: {  
    transport: 'SES',
    options: {
        AWSAccessKeyID: "AWSACCESSKEY",
        AWSSecretKey: "/AWS/SECRET"
    }
}

The first option is safer as stated on AWS Reference guide

Gmail

还可以利用 Gmail 发送邮件。如果你打算这样,我们建议你专门 创建一个新用户 ,最好不要使用现有的私人邮箱账户。

创建账号之后,就可以在 Ghost 的 config.js 文件中进行配置了。首先打开这个文件,然后找到需要设置邮件的运行环境所对应的配置处,修改邮件设置如下:

mail: {  
    transport: 'SMTP',
    options: {
        service: 'Gmail',
        auth: {
            user: 'youremail@gmail.com',
            pass: 'yourpassword'
        }
    }
}

来源地址

默认情况下,Ghost 发送的邮件都会将来源地址设置为 Blog Title <ghost@your-ghost-blog.com> – 其中,Blog Title 是你为博客设置的标题, your-ghost-blog.com 是在在 config.js 文件中设置的,如果你想自己定制,请在 config.js 文件中配置即可。

如果你只想重置邮箱地址,可以这样:

mail: {  
    from: 'myemail@address.com',
}

你还可以自定义名称:

mail: {  
    from: 'Custom Name <myemail@address.com>',
}

注意:Ghost 0.5.2 版本之前的配置参数叫做 fromaddress。现在已经 不赞成 使用了,请修改为 from

王赛
关于作者 王赛