> For the complete documentation index, see [llms.txt](https://easonwang.gitbook.io/web_basic/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://easonwang.gitbook.io/web_basic/yu_ming_she_ding/zhu-ce-yu-ming-xin-xiang/mailgun.md).

# mailgun

<https://www.mailgun.com/>

到網站照著步驟加入MX與TXT

![](/files/-M0u4_TQ5TMsdHTxH454)

然後按下下圖按鈕即可認證

![](/files/-M0u4_TSQMj34k7_gb4F)

最下面cname部分之前試都無法認證，還需要研究一下，但不影響發送郵件

\#避免垃圾郵件

1.domain跟發送郵件的from要相同

2.郵件內容跟主題要有內容

3.提供unsubscribe按鈕

4.確認有加入DKIM與SPF

## #接收郵件

先點選Route，然後設定要將你的domain接收的郵件導向哪個信箱

![](/files/-M0u4_TU6LlyR4TxVjnY)

然後設定

![](/files/-M0u4_TW5dVGoPZSlWI4)之後寫信給 `admin@rent.sakatu.com`

### 使用API發送郵件

這邊使用的是`mailgun-js`

```javascript
var api_key = "key-0000680b76ae7850b195bddb0b37a16a";
var domain = 'mail.sakatu.com';

exports.mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});
```

寄送

```javascript
var data = {
   from: 'Hello <no-reply@mail.sakatu.com>',
   to: req.body.email,
   subject: 'test',
   html: `content`
};
mailgun.messages().send(data, function (error, body) {
  if(err) console.log(err);
  console.log(body);
}
```

> 1.可以點選Mailgun網站上的Domains Tab中的Domain Information即可看到API key。
>
> 2.可以點選Mailgun網站上的Logs Tab查看是否發送成功。
>
> 之前發送給Gmail失敗出現`Free accounts are for test purposes only. Please upgrade or add the address to authorized recipients in Account Settings.` 訊息，之後加入信用卡後就發送成功了(剛加完寄送大約到等五分鐘才到)。
>
> 3.目前Hotmail會進入垃圾信箱。
>
> 4.目前Route設定hotmail信箱可能會產生以下錯誤。
>
> ```
> Please contact your Internet service provider since part of their network is on our block list (AS3140)
> ```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://easonwang.gitbook.io/web_basic/yu_ming_she_ding/zhu-ce-yu-ming-xin-xiang/mailgun.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
