From 926ccd7f06e10a4e516308b535927bf7c12626d0 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:26:17 +0100 Subject: [PATCH 01/25] New translations _index.md (Chinese Simplified) --- content/zh/_index.md | 91 +++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 48 deletions(-) diff --git a/content/zh/_index.md b/content/zh/_index.md index df5d1e8..b2cc868 100644 --- a/content/zh/_index.md +++ b/content/zh/_index.md @@ -1,147 +1,142 @@ --- -title: 欢迎使用 go-mail 文档 +title: Welcome to the go-mail documentation geekdocNav: false #geekdocAlign: center geekdocAnchor: false --- -[![GoDoc](https://godoc.org/github.com/wneessen/go-mail?status.svg)](https://pkg.go.dev/github.com/wneessen/go-mail) -[![codecov](https://codecov.io/gh/wneessen/go-mail/branch/main/graph/badge.svg?token=37KWJV03MR)](https://codecov.io/gh/wneessen/go-mail) -[![Go Report Card](https://goreportcard.com/badge/github.com/wneessen/go-mail)](https://goreportcard.com/report/github.com/wneessen/go-mail) -[![Crowdin](https://badges.crowdin.net/go-mail/localized.svg)](https://crowdin.com/project/go-mail) -[![GitHub release](https://img.shields.io/github/v/release/wneessen/go-mail)](https://github.com/wneessen/go-mail/releases/latest) -[![在 Awesome Go 中提到](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go) [![#go-mail on Discord](https://img.shields.io/badge/Discord-%23gomail-blue.svg)](https://discord.gg/dbfQyC4s) -[![REUSE status](https://api.reuse.software/badge/github.com/wneessen/go-mail)](https://api.reuse.software/info/github.com/wneessen/go-mail) +[![GoDoc](https://godoc.org/github.com/wneessen/go-mail?status.svg)](https://pkg.go.dev/github.com/wneessen/go-mail) [![codecov](https://codecov.io/gh/wneessen/go-mail/branch/main/graph/badge.svg?token=37KWJV03MR)](https://codecov.io/gh/wneessen/go-mail) [![Go Report Card](https://goreportcard.com/badge/github.com/wneessen/go-mail)](https://goreportcard.com/report/github.com/wneessen/go-mail) [![Crowdin](https://badges.crowdin.net/go-mail/localized.svg)](https://crowdin.com/project/go-mail) [![GitHub release](https://img.shields.io/github/v/release/wneessen/go-mail)](https://github.com/wneessen/go-mail/releases/latest) [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go) [![#go-mail on Discord](https://img.shields.io/badge/Discord-%23gomail-blue.svg)](https://discord.gg/dbfQyC4s) [![REUSE status](https://api.reuse.software/badge/github.com/wneessen/go-mail)](https://api.reuse.software/info/github.com/wneessen/go-mail) Mastodon Follow buy ma a coffee

go-mail logo

-go-mail 是一个易于使用的 Go 库,用于格式化和发送邮件。它使用惯用的 Go 风格,并遵循最佳实践和合理的默认值。该库仅依赖于 Go 标准库。 +go-mail is an easy to use Go library for formating and sending mails. It uses idiomatic Go style and follows best practice with sane defaults. The library only dependends on the Go Standard Library. -go-mail 的工作方式类似于编程式电子邮件客户端,并提供了许多您在 MUA 中考虑的标准方法和功能。 +go-mail works like a programatic email client and provides lots of methods and functionalities you would consider standard in a MUA.
-{{< button size="huge" relref="getting-started/introduction/" >}}开始使用 go-mail{{< /button >}} +{{< button size="huge" relref="getting-started/introduction/" >}}Get started using go-mail{{< /button >}}
-## 特色亮点 +## Feature highlights {{< columns >}} -### 仅依赖于标准库 +### Standard Library dependant -go-mail 不需要任何第三方模块,仅运行在 Go 标准库上 +go-mail does not require any third-party modules and only runs on the Go standard library <---> -### 现代、惯用的 Go +### Modern, idiomatic Go -我们使用现代和惯用的 Go 标准,遵循最先进的最佳实践和合理的默认值 +We are using modern and idiotmatic Go standards with this library and follow state-of-the-art best practices with sane defaults <---> -### 完整的 TLS 支持 +### Full TLS support -go-mail 支持不同策略的隐式 STARTTLS,以及用于发送邮件服务器的显式 SSL/TLS 的连接 +go-mail supports implicit STARTTLS with different policies as well as explicit SSL/TLS for connections to sending mail servers {{< /columns >}} {{< columns >}} -### 上下文 +### Contexts -我们利用 Go 上下文进行更好的控制流和超时/取消处理 +We make use of Go contexts for better control flow and timeout/cancelation handling <---> -### SMTP 认证 +### SMTP Authentication -支持三种常见的 SMTP 认证机制(LOGIN、PLAIN、CRAM-MD5)以及自定义身份验证。 +Support for three common SMTP authentication mechanisms (LOGIN, PLAIN, CRAM-MD5) as well as custom authentications. <---> -### 邮件地址验证 +### Mail address validation -go-mail 遵循 RFC5322 并验证提供的邮件地址 +go-mail follows RFC5322 and validates the provided mail addresses {{< /columns >}} {{< columns >}} -### 常见邮件头支持 +### Common mail header support -go-mail 提供了许多常见邮件头的生成器(Message-ID、Date、Bulk-Precedence、Priority 等) +go-mail brings generators for lots of common mail headers (Message-ID, Date, Bulk-Precedence, Priority, etc.) <---> -### 连接重用 +### Connection reusing -您可以在同一 SMTP 连接上发送多个邮件 +You can send mulitple mails over the same SMTP connection <---> -### 附件/嵌入 +### Attachments/Embeds -来自不同来源(本地文件系统、`io.Reader` 或 `embed.FS`)的附件和内联嵌入的完全支持 +Full support for attachments and inline embeds from different sources (local file system, `io.Reader` or `embed.FS`) {{< /columns >}} {{< columns >}} -### 编码和内容类型 +### Encodings and content types -go-mail 支持不同的编码和内容类型 +go-mail supports different encondings and content types out of the box <---> -### 中间件 +### Middlewares -第三方库的中间件支持,以便更改邮件消息以满足其需求 +Middleware support for 3rd-party libraries to alter mail message to their need <---> -### Sendmail 和文件存储 +### Sendmail and file storage -支持通过本地 sendmail 安装发送邮件消息以及输出到本地文件(例如作为磁盘上的 `.eml` 文件以在 MUA 中打开它们) +Support for sending mail messages through a local sendmail installation as well as output to local files (e. g. as `.eml` files to disk to open them in a MUA) {{< /columns >}} {{< columns >}} -### MDN 和 DSN +### MDNs and DSNs -go-mail 提供了请求 MDN(RFC 8098)和 DSN(RFC 1891)的支持 +go-mail brings support for requestng MDNs (RFC 8098) and DSNs (RFC 1891) <---> -### 模板支持 +### Template support -支持 Go 的 `html/template` 和 `text/template`(作为消息正文、替代部分或附件/嵌入) +Support for Go's `html/template` and `text/template` (as message body, alternative part or attachment/emebed) <---> -### DKIM 支持 +### DKIM support -通过 [go-mail-middlware/dkim](https://github.com/wneessen/go-mail-middleware/tree/main/dkim) 中间件的 DKIM 签名支持 +DKIM signature support via the [go-mail-middlware/dkim](https://github.com/wneessen/go-mail-middleware/tree/main/dkim) middleware {{< /columns >}} {{< columns >}} -### 调试日志记录 +### Debug logging -支持 SMTP 客户端将任何 SMTP 通信记录到 STDERR 以进行调试目的 +Support for the SMTP client to log any SMTP communication to STDERR for debug purposes <---> -### 自定义交付错误 +### Custom delivery errors -使用 `SendError` 类型,用户可以获取有关交付错误的详细信息,包括错误是否为临时性质 +With the `SendError` type the user is able to get detailed information about delivery errors including if the error is of temporary nature or not <---> {{< /columns >}} -## 支持 -我们在 Discord 上有一个支持和一般讨论频道。找到我们:[#go-mail](https://discord.gg/dbfQyC4s) +## Support +We have a support and general discussion channel on Discord. Find us at: [#go-mail](https://discord.gg/dbfQyC4s) + From 8a3569246dddd1ea64445da83260a9093067fbbf Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:26:19 +0100 Subject: [PATCH 02/25] New translations guide.md (Chinese Simplified) --- content/zh/community/guide.md | 127 +++++++++++++++++----------------- 1 file changed, 64 insertions(+), 63 deletions(-) diff --git a/content/zh/community/guide.md b/content/zh/community/guide.md index 9e1cfa2..3cff368 100644 --- a/content/zh/community/guide.md +++ b/content/zh/community/guide.md @@ -1,108 +1,109 @@ --- -title: 社区指南 +title: Community Guide --- -go-mail社区正在壮大,如果您正在阅读此文,那么您也想加入! +The go-mail community is growing and if you're reading this, chances are that you want to join, too! {{< toc >}} -## 资源 +## Resources -### 行为准则 +### Code of Conduct -在我们的社区中,我们遵循我们的[行为准则](https://github.com/wneessen/go-mail/blob/main/CODE_OF_CONDUCT.md),并要求每个想要参与的人都要相应地行事。 +In our community, we follow our [Code of Conduct](https://github.com/wneessen/go-mail/blob/main/CODE_OF_CONDUCT.md) and ask everybody who likes to participate to act accordingly. -### 支持和公告渠道 +### Support- and annoucement channels -* [Mastodon](https://s.pebcak.de/@go_mail/):在Mastodon上关注我们,以获取有关go-mail的最新消息 -* [go-mail论坛](https://github.com/wneessen/go-mail/discussions):接收有关go-mail的公告并开始讨论。 -* [Github问题](https://github.com/wneessen/go-mail/issues):如果您要报告错误或请求功能,请使用GitHub问题。请遵守每个存储库的问题模板中指定的规则。 -* [Discord](https://discord.gg/dbfQyC4s):go-mail开发人员和用户在此处实时会面和聊天的地方。 +* [Mastodon](https://s.pebcak.de/@go_mail/): Follow us on Mastodon to receive recent news about go-mail +* [go-mail forum](https://github.com/wneessen/go-mail/discussions): Receive announcements and start discussions about go-mail. +* [Github issues](https://github.com/wneessen/go-mail/issues): If you have a bug to report or feature to request, please use GitHub issues. Please respect the rules specified in each repository's issue template. +* [Discord](https://discord.gg/dbfQyC4s): A place for go-mail devs and users to meet and chat in real time. -## 贡献 +## Contributing -go-mail是一个开源的、社区驱动的项目。我们欢迎任何人加入我们为项目做出贡献。本文档旨在帮助任何希望熟悉项目和开发流程的人。 +go-mail is an open source, community driven project. We welcome anyone to join us in contributing to the project. This documentation is aimed at anyone wishing to get familiar with the project and the development processes. -* [开发新功能](#developing-new-features) -* [修复错误](#fixing-bugs) -* [测试](#testing) -* [文档](#documentation) -* [翻译](#translation) -* [支持](#support) +* [Developing new features](#developing-new-features) +* [Fixing bugs](#fixing-bugs) +* [Testing](#testing) +* [Documenation](#documentation) +* [Translation](#translation) +* [Support](#support) -### 开发新功能 +### Developing New Features -我们始终热衷于为go-mail添加新功能。添加新功能的过程如下: +We are always keen to add features to go-mail. The process for adding new features are as follows: -* 在Github的[问题部分](https://github.com/wneessen/go-mail/issues)中检查带有“TODO”或“help wanted”标签的可用问题 -* 如果没有找到打开的“TODO”/“help wanted”问题或您想要的功能未涵盖,请为该特定功能打开一个提案问题,并等待项目维护者的“OK” -* 开发之前,请检查问题是否包括以下信息: - * 增强的目的 - * 增强范围之外的内容 -* 如果问题不包括此信息,请随时向打开问题的人请求信息。有时会创建占位符问题并需要更多详细信息 -* 在问题上发表评论,说明您希望开发该功能 -* 克隆存储库并创建格式为`feature/_`的分支 -* 新功能通常需要文档,因此请确保您还添加或更新了文档作为更改的一部分 -* 请确保您的代码具有所需的测试覆盖范围 -* 一旦功能准备好进行测试,请创建草案PR。请确保PR说明中列出了测试场景和测试用例,并带有复选框,以便其他人知道仍需测试什么 -* 一旦所有测试都完成,请从草案中更新PR的状态并留言 +* Check the [issue section on Github](https://github.com/wneessen/go-mail/issues) for available issues with the "TODO" or "help wanted" tag +* If no open "TODO"/"help wanted" issue is found or the feature you have in mind is not covered, please open a proposal issue for that specific feature and wait for the "OK" from the project maintainers +* Before developing, check that the issue includes the following information: + * The purpose of the enhancement + * What is out of scope for the enhancement +* If the issue does not include this information, feel free to request the information from the person who opened the issue. Sometimes placeholder issues are created and require more details +* Comment on the issue stating if you wish to develop the feature +* Clone the repository and create a branch with the format `feature/_` +* New features often require documentation so please ensure you have also added or updated the documentation as part of the changes +* Please make sure that your code has the required test coverage +* Once the feature is ready for testing, create a draft PR. Please ensure the PR description has the test scenarios and test cases listed with checkmarks, so that others can know what still needs to be tested +* Once all the testing is completed, please update the status of the PR from draft and leave a message {{< hint type=important >}} -未附带相应问题的任何PR可能会被拒绝。 +Any PRs opened without a corresponding issue may be rejected. {{< /hint >}} -### 修复错误 +### Fixing bugs -修复错误的过程如下: +The process for fixing bugs are as follows: -* 检查[Github问题](https://github.com/wneessen/go-mail/issues)并选择要修复的错误 -* 开发之前,请检查问题是否包括以下信息: - * 受影响的平台范围 - * 重现步骤。有时会打开不是go-mail问题的错误,并且责任在于报告人证明它是具有最小可重现示例的go-mail问题 -* 如果问题不包括此信息,请随时向打开问题的人请求信息 -* 在问题上发表评论,说明您希望开发修复程序 -* 克隆存储库并创建格式为`bugfix/_`的分支 -* 一旦修复程序准备好进行测试,请创建草案PR。请确保PR说明中列出了测试场景和测试用例,并带有复选框,以便其他人知道仍需测试什么 -* 一旦所有测试都完成,请从草案中更新PR的状态并留言。 +* Check the [Github issues](https://github.com/wneessen/go-mail/issues) and select a bug to fix +* Before developing, check that the issue includes the following information: + * The scope of the issue including platforms affected + * The steps to reproduce. Sometimes bugs are opened that are not go-mail issues and the onus is on the reporter to prove that it is a go-mail issue with a minimal reproducible example +* If the issue does not include this information, feel free to request the information from the person who opened the issue +* Comment on the issue stating you wish to develop a fix +* Clone the repository and create a branch with the format `bugfix/_` +* Once the fix is ready for testing, create a draft PR. Please ensure the PR description has the test scenarios and test cases listed with checkmarks, so that others can know what still needs to be tested +* Once all the testing is completed, please update the status of the PR from draft and leave a message. {{< hint type=note >}} -没有任何阻止您打开问题并自己解决它,但请注意,所有错误修复都应该进行讨论,因为方法可能会产生意外的副作用。 +There is nothing stopping you from opening a issue and working on it yourself, but please be aware that all bugfixes should be discussed as the approach may have unintended side effects. {{< /hint >}} - + {{< hint type=important >}} -未附带相应问题的任何PR可能会被拒绝。 +Any PRs opened without a corresponding issue may be rejected. {{< /hint >}} -### 测试 +### Testing + +Testing is vitally important to ensure quality in the project. There are a couple of scenarios where testing can really help the project: -测试对于确保项目质量至关重要。有几种情况下,测试可以真正帮助项目: +* Testing if a bug is reproducible on your local system +* Testing PRs to ensure that they work correctly -* 测试是否可以在本地系统上重现错误 -* 测试PR以确保它们正常工作 +If you chose to test if someone's bug report is reproducible on your local system, then feel free to add a comment on the issue confirming this with the output of your test program. -如果您选择测试某人的错误报告是否可以在本地系统上重现,则可以在问题上添加评论,确认这一点,并附上测试程序的输出。 +To test PRs, choose a PR to test and check if the PR description has the testing scenarios listed. If not, please ask the person who opened the PR to provide that list. Once you have determined a valid test scenario, please report your findings on the PR. -要测试PR,请选择要测试的PR并检查PR说明中是否列出了测试场景。如果没有,请要求打开PR的人提供该列表。一旦确定了有效的测试场景,请在PR上报告您的发现。 +If you ever need more clarity or help on testing, please ask a question in the [Github forum](https://github.com/wneessen/go-mail/discussions) or on [Discord](https://discord.gg/dbfQyC4s). -如果您需要更多的明确或帮助进行测试,请在[Github论坛](https://github.com/wneessen/go-mail/discussions)或[Discord](https://discord.gg/dbfQyC4s)上提问。 +### Documentation -### 文档 +While we require proper GoDoc documenation comments in the code, this website is meant as more in-depth documenation of features and the project itself. -虽然我们要求代码中有适当的GoDoc文档注释,但本网站旨在更深入地记录功能和项目本身的文档。 +Since documenattion is hard and the website is still in an incomplete state, any contribution to this is greatly appreciated. Features without documentation are condidered "unfinished" to the project, it's as important as the code. -由于文档很难,网站仍处于不完整状态,因此对此的任何贡献都将不胜感激。没有文档的功能被认为是“未完成”的项目,它与代码一样重要。 +The website is built on Hugo using the Geekdocs theme. It's very simple and basically consists of markdown files. There are instructions on how to install the website on your local computer in the [website's repository](https://github.com/wneessen/go-mail-website). -该网站基于Hugo使用Geekdocs主题构建。它非常简单,基本上由Markdown文件组成。在[网站的存储库](https://github.com/wneessen/go-mail-website)中有有关如何在本地计算机上安装网站的说明。 +### Translation -### 翻译 +The default documents of the go-mail project are English documents. We use the "Crowdin" tool to translate documents in other languages and synchronize them to the website. You can [join our project](https://translations.go-mail.dev) and submit your translations to make contributions. -go-mail项目的默认文档是英文文档。我们使用“Crowdin”工具将其他语言的文档翻译并同步到网站上。您可以[加入我们的项目](https://translations.go-mail.dev)并提交您的翻译以进行贡献。 +Currently the only supported 2nd language is German, but we are keen to add other languages as well. Please request them via a Github issue in the go-mail-website repository. -目前,唯一支持的第二种语言是德语,但我们也热衷于添加其他语言。请通过go-mail-website存储库中的Github问题请求它们。 +### Support -### 支持 +A great way to contribute to the project is to help others who are experiencing difficulty. This is normally reported as a issue or a message on the `#go-mail` [Discord channel](https://discord.gg/dbfQyC4s). Even just clarifying the issue can really help out. Sometimes, when an issue is discussed and gets resolved, we create a guide out of it to help others who face the same issues. -为项目做出贡献的一个很好的方法是帮助那些遇到困难的人。这通常报告为问题或在`#go-mail` [Discord频道](https://discord.gg/dbfQyC4s)上的消息。即使只是澄清问题,也可以真正帮助。有时,当问题得到讨论并得到解决时,我们会将其制作成指南,以帮助其他面临相同问题的人。 From 63ebdcf0db100c90be2844611a4a85223b7690a9 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:26:20 +0100 Subject: [PATCH 03/25] New translations _index.md (Chinese Simplified) --- content/zh/getting-started/_index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/zh/getting-started/_index.md b/content/zh/getting-started/_index.md index c33c95c..4268c7c 100644 --- a/content/zh/getting-started/_index.md +++ b/content/zh/getting-started/_index.md @@ -1,4 +1,5 @@ --- title: Getting started weight: -20 ---- \ No newline at end of file +--- + From 026013f6b758697afe6816a3f6be02adec1f3dcd Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:26:22 +0100 Subject: [PATCH 04/25] New translations introduction.md (Chinese Simplified) --- content/zh/getting-started/introduction.md | 107 +++++++++++---------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/content/zh/getting-started/introduction.md b/content/zh/getting-started/introduction.md index e12b3c0..566cc34 100644 --- a/content/zh/getting-started/introduction.md +++ b/content/zh/getting-started/introduction.md @@ -1,120 +1,121 @@ --- -title: 简介 +title: Introduction weight: -20 --- -这篇简短的教程向您展示了如何从安装到发送第一封邮件使用go-mail。 +This short tutorial shows you how to get up and running with go-mail from installation to sending your first mail. {{< toc >}} -## 要求 +## Requirements -go-mail需要一个工作的Go安装(版本1.16+)。从[Go下载页面](https://go.dev/dl/)下载Go。 +go-mail requires a working Go installation (Version 1.16+). Download Go from the [Go Downloads Page](https://go.dev/dl/). -## 安装 +## Installation -可以使用Go模块安装机制通过`go get`命令安装go-mail。 +go-mail can be installed using the Go module installation mechanism via the `go get` command. -要安装go-mail的最新版本,请进入您的项目文件夹,然后通过发出以下命令导入模块即可: +To install the latest version of go-mail, enter your project folder and simply import the module by issuing the following command: ```shell $ go get github.com/wneessen/go-mail ``` -## 发送您的第一封邮件 +## Sending your first mail -go-mail由两个主要组件组成。 `Msg`表示邮件消息,`Client`通过SMTP服务处理邮件传递。 +go-mail consists of two main components. The `Msg` which represents the mail message and the `Client` which takes care of the mail delivery via a SMTP service. -### 创建新消息 +### Create a new message -首先,让我们使用`NewMsg()`方法创建一个新的`Msg`,并分配一个发件人地址和一个收件人地址。 +First let's create a new `Msg` using the `NewMsg()` method and assign a sender address as well as a recipient address. ```go package main import ( - "github.com/wneessen/go-mail" - "log" + "github.com/wneessen/go-mail" + "log" ) func main() { - m := mail.NewMsg() - if err := m.From("toni.sender@example.com"); err != nil { - log.Fatalf("failed to set From address: %s", err) - } - if err := m.To("tina.recipient@example.com"); err != nil { - log.Fatalf("failed to set To address: %s", err) - } + m := mail.NewMsg() + if err := m.From("toni.sender@example.com"); err != nil { + log.Fatalf("failed to set From address: %s", err) + } + if err := m.To("tina.recipient@example.com"); err != nil { + log.Fatalf("failed to set To address: %s", err) + } } ``` -在这个小代码片段中,首先我们将go-mail导入我们的项目。请参见[第4行](#hl-1-4)中的`import`语句。接下来,我们在[第9行](#hl-1-9)中创建了一个新消息。第[10](#hl-1-10)和[13](#hl-1-13)行设置了发件人和收件人地址。由于go-mail确保您提供的是有效的邮件地址,因此我们返回一个`error`。这样我们就可以确保go-mail接受提供的地址,并且不会在以后引起问题。 +In this little code snippet, first and foremost we import go-mail into our project. See the `import` statement in [line 4](#hl-1-4). Next we create a new message in [line 9](#hl-1-9). Lines [10](#hl-1-10) and [13](#hl-1-13) set the sender and recipient addresses. Since go-mail makes sure that you are providing valid mail addresses, we return an `error`. This way we can make sure that the provided address is accepted by go-mail and will not cause problems later on. -接下来,我们要为我们的邮件设置一个主题行,并填充邮件正文内容。 +Next we want to set a subject line for our message and fill the mail body with some content. ```go m.Subject("This is my first mail with go-mail!") m.SetBodyString(mail.TypeTextPlain, "Do you like this mail? I certainly do!") ``` -`SetBodyString()`的第一个参数是我们需要提供的内容类型。在我们的示例中,`mail.TypeTextPlain`基本上表示`text/plain`内容类型-表示纯文本邮件正文。 +The first argument for `SetBodyString()` is a content type we need to provide. In our example the `mail.TypeTextPlain` basically represents a `text/plain` content type - meaning a plain text mail body. -### 发送邮件 +### Sending the mail -现在我们已经准备好发送邮件消息了,让我们将其发送出去。为此,我们将使用`Client`,它处理SMTP传输。 +Now that we have our mail message ready to go, let's bring it on the way and send it out. For this we'll use the `Client`, which handles the SMTP transmission. ```go c, err := mail.NewClient("smtp.example.com", mail.WithPort(25), mail.WithSMTPAuth(mail.SMTPAuthPlain), - mail.WithUsername("my_username"), mail.WithPassword("extremely_secret_pass")) + mail.WithUsername("my_username"), mail.WithPassword("extremely_secret_pass")) if err != nil { - log.Fatalf("failed to create mail client: %s", err) + log.Fatalf("failed to create mail client: %s", err) } ``` -在此示例中,我们使用主机名`smtp.example.com`连接到邮件服务器,并为`Client`提供了一些选项,例如我们要连接的端口,我们要使用`SMTP PLAIN`进行身份验证以及用户名和密码。 +In this example we connect to the mail server with the hostname `smtp.example.com` and provide the `Client` with a couple of options like the port we want to connect to, the fact that we want to use `SMTP PLAIN` for authentication and the username and password. -最后,我们告诉客户端交付邮件。 +Finally we tell the client to deliver the mail. ```go if err := c.DialAndSend(m); err != nil { - log.Fatalf("failed to send mail: %s", err) + log.Fatalf("failed to send mail: %s", err) } ``` -`DialAndSend()`方法负责建立连接并发送邮件。您也可以分别调用它们,但是我们不需要快速示例。 +The `DialAndSend()` method takes care of establishing the connection and sending out the mail. You have the option to call them separately as well, but we won't need this for the quick example. -## 结论 +## Conclusion -那很简单,不是吗?您成功地准备了一封邮件消息,并通过第三方邮件服务器将其发送给收件人。当然,go-mail可以做更多。查看详细文档以获取所有功能。 +That was quite simple, wasn't it? You successfully prepared a mail message and delivered it to the recipient via a 3rd party mail server. go-mail of course can do much more. Check out the in-depth documentation for all the features. -## 完整示例代码 +## Full example code ```go package main import ( - "github.com/wneessen/go-mail" - "log" + "github.com/wneessen/go-mail" + "log" ) func main() { - m := mail.NewMsg() - if err := m.From("toni.sender@example.com"); err != nil { - log.Fatalf("failed to set From address: %s", err) - } - if err := m.To("tina.recipient@example.com"); err != nil { - log.Fatalf("failed to set To address: %s", err) - } - m.Subject("This is my first mail with go-mail!") - m.SetBodyString(mail.TypeTextPlain, "Do you like this mail? I certainly do!") - c, err := mail.NewClient("smtp.example.com", mail.WithPort(25), mail.WithSMTPAuth(mail.SMTPAuthPlain), - mail.WithUsername("my_username"), mail.WithPassword("extremely_secret_pass")) - if err != nil { - log.Fatalf("failed to create mail client: %s", err) - } - if err := c.DialAndSend(m); err != nil { - log.Fatalf("failed to send mail: %s", err) - } + m := mail.NewMsg() + if err := m.From("toni.sender@example.com"); err != nil { + log.Fatalf("failed to set From address: %s", err) + } + if err := m.To("tina.recipient@example.com"); err != nil { + log.Fatalf("failed to set To address: %s", err) + } + m.Subject("This is my first mail with go-mail!") + m.SetBodyString(mail.TypeTextPlain, "Do you like this mail? I certainly do!") + c, err := mail.NewClient("smtp.example.com", mail.WithPort(25), mail.WithSMTPAuth(mail.SMTPAuthPlain), + mail.WithUsername("my_username"), mail.WithPassword("extremely_secret_pass")) + if err != nil { + log.Fatalf("failed to create mail client: %s", err) + } + if err := c.DialAndSend(m); err != nil { + log.Fatalf("failed to send mail: %s", err) + } } +``` \ No newline at end of file From 78a6943872b5fe92efa9f148497788748149abe1 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:26:24 +0100 Subject: [PATCH 05/25] New translations _index.md (Chinese Simplified) --- content/zh/reference/_index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/zh/reference/_index.md b/content/zh/reference/_index.md index 2eab206..8e9ca60 100644 --- a/content/zh/reference/_index.md +++ b/content/zh/reference/_index.md @@ -1,4 +1,5 @@ --- title: Reference weight: -20 ---- \ No newline at end of file +--- + From 214425db54c81b0f1bd4476ef05d0caf258d53e8 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:26:26 +0100 Subject: [PATCH 06/25] New translations _index.md (Chinese Simplified) --- content/zh/reference/client/_index.md | 118 +++++++++++++------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/content/zh/reference/client/_index.md b/content/zh/reference/client/_index.md index 2172e3e..7006431 100644 --- a/content/zh/reference/client/_index.md +++ b/content/zh/reference/client/_index.md @@ -1,8 +1,8 @@ --- -title: 邮件发送客户端 +title: The mail delivery client --- -在 go-mail 中,`Client` 负责通过 SMTP 协议与远程邮件服务器进行邮件传递。 +In go-mail the `Client` is responsible for the mail delivery with remote mail servers that communicate via the SMTP protocol. {{< toc >}} @@ -24,19 +24,19 @@ package main import "github.com/wneessen/go-mail" func main() { - c, err := mail.NewClient("mail.example.com") - if err != nil { - panic(err) - } + c, err := mail.NewClient("mail.example.com") + if err != nil { + panic(err) + } } ``` {{< /tab >}} {{< /tabs >}} -要创建新的 `Client`,您可以使用 `NewClient()` 方法。作为第一个参数,它需要发送 SMTP 服务器的主机名。您可以选择提供一系列 `Option` 函数。这些选项函数可用于覆盖 `Client` 的默认设置。 +To create a new `Client`, you can use the `NewClient()` method. As first argument it requires the hostname of the sending SMTP server. Optionally you can provide a list of `Option` funcionts. These option functions can be used to override the default settings of the `Client`. -有关所有可用选项的详细信息,请查看 [Options](options) 文档。 +Check the [Options](options) documentation for in-depth details to all available Options. ## Client @@ -45,7 +45,7 @@ func main() { ```go type Client struct { -// 包含过滤或未导出字段 +// contains filtered or unexported fields } ``` @@ -70,18 +70,18 @@ package main import "github.com/wneessen/go-mail" func main() { - c, err := mail.NewClient("mail.example.com") - if err != nil { - panic(err) - } - defer c.Close() + c, err := mail.NewClient("mail.example.com") + if err != nil { + panic(err) + } + defer c.Close() } ``` {{< /tab >}} {{< /tabs >}} -`Close()` 关闭 `Client` 连接到的 SMTP 服务器的连接。如果 `Client` 没有活动连接或关闭连接失败,则返回 `error`。 +`Close()` closes the connection to the SMTP server the `Client` is connected to. It returns an `error` in case the `Client` has no active connection or if closing the connection fails. ### DialAndSend() @@ -101,33 +101,33 @@ package main import "github.com/wneessen/go-mail" func main() { - from := "Toni Tester " - to := "Alice " - server := "mail.example.com" - - m := mail.NewMsg() - if err := m.From(from); err != nil { - panic(err) - } - if err := m.To(to); err != nil { - panic(err) - } - m.Subject("This is a great subject") - - c, err := mail.NewClient(server) - if err != nil { - panic(err) - } - if err := c.DialAndSend(m); err != nil { - panic(err) - } + from := "Toni Tester " + to := "Alice " + server := "mail.example.com" + + m := mail.NewMsg() + if err := m.From(from); err != nil { + panic(err) + } + if err := m.To(to); err != nil { + panic(err) + } + m.Subject("This is a great subject") + + c, err := mail.NewClient(server) + if err != nil { + panic(err) + } + if err := c.DialAndSend(m); err != nil { + panic(err) + } } ``` {{< /tab >}} {{< /tabs >}} -`DialAndSend()` 方法是 [DialAndSendWithContext()](#dialandsendwithcontext) 的别名,使用默认的 `context.Background` 上下文。`DialAndSend()` 接受一个或多个 `Msg` 指针作为参数,并在执行任何操作失败时返回 `error`。 +The `DialAndSend()` method is an alias for [DialAndSendWithContext()](#dialandsendwithcontext) with a default `context.Background` context. `DialAndSend()` takes a list of `Msg` pointer as argument(s) and returns an `error` in case any of the performed actions fails. ### DialAndSendWithContext() @@ -147,33 +147,33 @@ package main import "github.com/wneessen/go-mail" func main() { - from := "Toni Tester " - to := "Alice " - server := "mail.example.com" - - m := mail.NewMsg() - if err := m.From(from); err != nil { - panic(err) - } - if err := m.To(to); err != nil { - panic(err) - } - m.Subject("This is a great subject") - - c, err := mail.NewClient(server) - if err != nil { - panic(err) - } - ctx := context.Background() - if err := c.DialAndSendWithContext(ctx, m); err != nil { - panic(err) - } + from := "Toni Tester " + to := "Alice " + server := "mail.example.com" + + m := mail.NewMsg() + if err := m.From(from); err != nil { + panic(err) + } + if err := m.To(to); err != nil { + panic(err) + } + m.Subject("This is a great subject") + + c, err := mail.NewClient(server) + if err != nil { + panic(err) + } + ctx := context.Background() + if err := c.DialAndSendWithContext(ctx, m); err != nil { + panic(err) + } } ``` {{< /tab >}} {{< /tabs >}} -`DialAndSendWithContext()` 是 `Client` 上的一站式快捷方法。一旦创建了 `Client`,调用 `DialAndSendWithContext()` 方法将使其连接到配置的服务器,发送给定的邮件 `Msg`,然后通过再次关闭连接来完成。 +The `DialAndSendWithContext()` is a one-for-all shortcut method on the `Client`. Once the `Client` is created, calling the `DialAndSendWithContext()` method will have it connect to the configured server, send out the given mail `Msg` and finalize by closing the connection again. -该方法的第一个参数是 `context.Context`,后跟一个或多个 `Msg` 指针。`DialAndSendWithContext()` 在执行任何操作失败时返回 `error`。 +The first argument of the method is a `context.Context` followed by a list of one or more `Msg` pointers. `DialAndSendWithContext()` does return an `error` in case any of the performed actions fails. \ No newline at end of file From 26f3a6e3a7128ecd68c2303b86c8a11b884b3646 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:26:28 +0100 Subject: [PATCH 07/25] New translations options.md (Chinese Simplified) --- content/zh/reference/client/options.md | 65 +++++++++++++------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/content/zh/reference/client/options.md b/content/zh/reference/client/options.md index 7f2bcf4..b237fd5 100644 --- a/content/zh/reference/client/options.md +++ b/content/zh/reference/client/options.md @@ -1,5 +1,5 @@ --- -title: 客户端选项 +title: Client options --- {{< toc >}} @@ -14,7 +14,7 @@ type Option func(*Client) error {{< /tab >}} {{< /tabs >}} -`Option` 是可选参数函数,可以用作 `NewClient()` 方法的可选参数,以覆盖返回的 `Client` 的默认值。 +Client `Option` are functions that can be used as optional arguments for the `NewClient()` methods to override the default vaules of the returned `Client`. ### WithDebugLog() {{< tabs "WithDebugLog" >}} @@ -32,7 +32,7 @@ import "github.com/wneessen/go-mail" func main() { c, err := mail.NewClient("mail.example.com", mail.WithDebugLog()) if err != nil { - panic(err) + panic(err) } } ``` @@ -42,11 +42,11 @@ Introduced in [go-mail v0.3.9](https://github.com/wneessen/go-mail/releases/tag/ {{< /tab >}} {{< /tabs >}} -`WithDebugLog` 启用 SMTP 流量的调试日志。启用后,客户端与服务器之间的任何 SMTP 通信都会记录到 `os.Stderr`。 +`WithDebugLog` enables debug logging of SMTP traffic on the `Client`. When enabled, any SMTP communication from the client to the server and vice-versa is logged to `os.Stderr`. -在输出中,`C --> S` 是客户端到服务器的通信,`C <-- S` 表示服务器到客户端的通信。 +In the output `C --> S` is the communication from the client to the server and `C <-- S` represents the communication back from the server to the client. -以下是输出示例: +Here is an output example: ``` 2023/01/15 20:21:18 [DEBUG] C --> S: EHLO client.example.com 2023/01/15 20:21:18 [DEBUG] C <-- S: 250 server.example.com @@ -101,16 +101,16 @@ func main() { {{< /tab >}} {{< /tabs >}} -`WithDSN` 选项函数告诉 `Client` 请求 DSN(如果服务器支持)如[RFC 1891](https://rfc-editor.org/rfc/rfc1891.html)所述。 +The `WithDSN` option function tells the `Client` to request DSNs (if the server supports it) as described in [RFC 1891](https://rfc-editor.org/rfc/rfc1891.html). -DSN(传递状态通知)是 SMTP 协议的扩展,需要发送服务器支持。DSN 的 RFC 定义了不同的参数,我们已经实现了我们认为对 go-mail 最有意义的参数: +DSNs (Delivery Status Notification) are an extension to the SMTP protocol and need to be supported by the sending server. The RFC for DSNs defines different parameters of which we've implemented the once which we think make most sense for go-mail: -* `MAIL FROM` 命令的 `RET` 扩展,让用户指定 DSN 是否应包含发送邮件的全部内容(`FULL`)或仅包含邮件头(`HDRS`)。 -* `NOTIFY` 扩展允许用户为不同类型的允许情况请求 DSN:`NEVER`、`SUCCESS`、`FAILURE` 和 `DELAY` +* The `RET` extension for the `MAIL FROM` command, to let the user specify if a DSN should contain the full mail (`FULL`) or only headers (`HDRS`) of the sent mail. +* The `NOTIFY` extension that allows the user to request a DSN for the different types of allowed situations: `NEVER`, `SUCCESS`, `FAILURE` and `DELAY` -`ENVID` 和 `ORCPT` 目前不受支持,但可能会在以后的版本中跟进(如果您认为这很有用,请打开一个 [issue](https://github.com/wneessen/go-mail/issues/new/choose))。 +`ENVID` and `ORCPT` are currently not supported but might follow in a later relaese (please open an [issue](https://github.com/wneessen/go-mail/issues/new/choose) if you see usefulness in this). -默认情况下,`WithDSN()` 设置 `FULL` 的 *Mail From Return Option* 和 `SUCCESS` 和 `FAILURE` 的 *Recipient Notify Options*。如果您想使用其他 DSN 设置,请参阅 [WithDSNMailReturnType](#withdsnmailreturntype) 和 [WithDSNRcptNotifyType](#withdsnrcptnotifytype) 的文档。 +By default `WithDSN()` sets the `FULL` *Mail From Return Option* and the `SUCCESS` and `FAILURE` *Recipient Notify Options*. If you like to use other settings for the DSN, please see the documentation for [WithDSNMailReturnType](#withdsnmailreturntype) and [WithDSNRcptNotifyType](#withdsnrcptnotifytype) ### WithDSNMailReturnType() {{< tabs "WithDSNMailReturnType" >}} @@ -128,21 +128,21 @@ import "github.com/wneessen/go-mail" func main() { c, err := mail.NewClient("mail.example.com", mail.WithDSNMailReturnType(mail.DSNMailReturnFull)) if err != nil { - panic(err) + panic(err) } } ``` {{< /tab >}} {{< /tabs >}} -`WithDSNMailReturnType` 启用 `Client` 请求 DSN,如[RFC 1891](https://www.rfc-editor.org/rfc/rfc1891)所述,并将 `MAIL FROM` 返回选项类型设置为给定的 `DSNMailReturnOption`。 +`WithDSNMailReturnType` enables the `Client` to request DSNs (if the server supports it) as described in the [RFC 1891](https://www.rfc-editor.org/rfc/rfc1891) and set the `MAIL FROM` Return option type to the given `DSNMailReturnOption` -go-mail 已经内置了以下两种 `DSNMailReturnOption` 类型: +go-mail has the following two `DSNMailReturnOption` type already built-in: -* `DSNMailReturnHeadersOnly`:请求仅返回邮件的头部。\ - 参见:[RFC 1891,第5.3节](https://www.rfc-editor.org/rfc/rfc1891#section-5.3) -* `DSNMailReturnFull`:请求在为此收件人发出“失败”的传递状态通知时返回整个消息。\ - 参见:[RFC 1891,第5.3节](https://www.rfc-editor.org/rfc/rfc1891#section-5.3) +* `DSNMailReturnHeadersOnly`: requests that only the headers of the message be returned. \ + See: [RFC 1891, Section 5.3](https://www.rfc-editor.org/rfc/rfc1891#section-5.3) +* `DSNMailReturnFull`: requests that the entire message be returned in any "failed" delivery status notification issued for this recipient \ + See: [RFC 1891, Section 5.3](https://www.rfc-editor.org/rfc/rfc1891#section-5.3) ### WithDSNRcptNotifyType() @@ -161,27 +161,26 @@ import "github.com/wneessen/go-mail" func main() { c, err := mail.NewClient("mail.example.com", mail.WithDSNRcptNotifyType(mail.DSNRcptNotifyFailure, mail.DSNRcptNotifyDelay, - mail.DSNRcptNotifySuccess)) + mail.DSNRcptNotifySuccess)) if err != nil { - panic(err) + panic(err) } } ``` {{< /tab >}} {{< /tabs >}} -`WithDSNRcptNotifyType` 启用 `Client` 请求 DSN,如[RFC 1891](https://rfc-editor.org/rfc/rfc1891.html)所述,并将 `RCPT TO` 通知选项设置为给定的 `DSNRcptNotifyOption` 列表。 +`WithDSNRcptNotifyType` enables the `Client` to request DSNs as described in [RFC 1891](https://www.rfc-editor.org/rfc/rfc1891) and sets the `RCPT TO` notify options to the given list of `DSNRcptNotifyOption` -go-mail 已经内置了以下 `DSNRcptNotifyOption` 类型: +go-mail has the following `DSNRcptNotifyOption` types already built-in: -* `DSNRcptNotifyNever`:不要在任何情况下向发送方返回 DSN。\ - 参见:[RFC 1891,第5.1节](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) -* `DSNRcptNotifySuccess`:请求在成功传递时发出 DSN\ - 参见:[RFC 1891,第5.1节](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) -* `DSNRcptNotifyFailure`:请求在传递失败时发出 DSN\ - 参见:[RFC 1891,第5.1节](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) -* `DSNRcptNotifyDelay`:表示发送方愿意接收“延迟”的 DSN。如果消息的传递已经被延迟了不寻常的时间(由消息被延迟的 MTA 确定),但无法确定最终的传递状态(无论成功还是失败),则可以发出延迟的 DSN。在 NOTIFY 参数中缺少 DELAY 关键字会要求在任何情况下都不发出“延迟”的 DSN。\ - 参见:[RFC 1891,第5.1节](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) +* `DSNRcptNotifyNever`: requests that a DSN not be returned to the sender under any conditions. \ + See: [RFC 1891, Section 5.1](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) +* `DSNRcptNotifySuccess`: requests that a DSN be issued on successful delivery \ + See: [RFC 1891, Section 5.1](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) +* `DSNRcptNotifyFailure`: requests that a DSN be issued on delivery failure \ + See: [RFC 1891, Section 5.1](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) +* `DSNRcptNotifyDelay`: indicates the sender's willingness to receive "delayed" DSNs. Delayed DSNs may be issued if delivery of a message has been delayed for an unusual amount of time (as determined by the MTA at which the message is delayed), but the final delivery status (whether successful or failure) cannot be determined. The absence of the DELAY keyword in a NOTIFY parameter requests that a "delayed" DSN NOT be issued under any conditions. See: [RFC 1891, Section 5.1](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) ### WithHELO() @@ -200,11 +199,11 @@ import "github.com/wneessen/go-mail" func main() { c, err := mail.NewClient("mail.example.com", mail.WithHELO("test.example.com")) if err != nil { - panic(err) + panic(err) } } ``` {{< /tab >}} {{< /tabs >}} -`WithHELO` 指示 `Client` 使用提供的字符串作为 HELO/EHLO 问候主机。默认情况下,`Client` 将使用 Go 的 `os.Hostname()` 方法获取本地主机名,并将其用于 HELO/EHLO 问候。`WithHELO` 将覆盖此设置。 +`WithHELO` instructs the `Client` to use the provided string as HELO/EHLO greeting host. By default the `Client` will use Go's `os.Hostname()` method to get the local hostname and use that for the HELO/EHLO greeting. `WithHELO` will override this. \ No newline at end of file From d2dee693605c5a85e2a653586719c7a8609e62a1 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:26:30 +0100 Subject: [PATCH 08/25] New translations _index.md (Chinese Simplified) --- content/zh/examples/_index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/zh/examples/_index.md b/content/zh/examples/_index.md index 8dce9f9..b814729 100644 --- a/content/zh/examples/_index.md +++ b/content/zh/examples/_index.md @@ -1,4 +1,5 @@ --- title: Examples weight: -20 ---- \ No newline at end of file +--- + From cad0d866eba1d1f030e7a26ffbf0642b7831f6c3 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:26:32 +0100 Subject: [PATCH 09/25] New translations bulk-mailer.md (Chinese Simplified) --- content/zh/examples/bulk-mailer.md | 163 ++++++++++++++++------------- 1 file changed, 89 insertions(+), 74 deletions(-) diff --git a/content/zh/examples/bulk-mailer.md b/content/zh/examples/bulk-mailer.md index 41346a1..105652f 100644 --- a/content/zh/examples/bulk-mailer.md +++ b/content/zh/examples/bulk-mailer.md @@ -1,39 +1,39 @@ --- -title: 批量邮件示例 +title: Bulk Mailer Example --- -在这个示例中,我们创建了一个小型的批量邮件发送程序,可以将相同的邮件发送给更多的收件人。对于我们来说,重要的是直接在邮件中寻址收件人,因此我们将使用Go的`html/template`和`text/template`系统以及占位符。 +In this example we create a small bulk mailer for sending out the same mail to a bigger list of recipients. It is important for us to address the recipient directly in the mail, therefore we will make use of Go's `html/template` and `text/template` system together with placeholders. ```go package main import ( - "fmt" - ht "html/template" - "log" - "math/rand" - "os" - tt "text/template" - "time" - - "github.com/wneessen/go-mail" + "fmt" + ht "html/template" + "log" + "math/rand" + "os" + tt "text/template" + "time" + + "github.com/wneessen/go-mail" ) -// User是一个简单的类型,允许我们设置名字,姓氏和邮件地址 +// User is a simple type allowing us to set a firstname, lastname and mail address type User struct { - Firstname string - Lastname string - EmailAddr string + Firstname string + Lastname string + EmailAddr string } -// 我们的发件人信息将用于FROM地址字段 +// Our sender information that will be used in the FROM address field const ( - senderName = "ACME Inc." - senderAddr = "noreply@acme.com" + senderName = "ACME Inc." + senderAddr = "noreply@acme.com" ) const ( - textBodyTemplate = `Hi {{.Firstname}}, + textBodyTemplate = `Hi {{.Firstname}}, we are writing your to let you know that this week we have an amazing offer for you. Using the coupon code "GOMAIL" you will get a 20% discount on all our products in our @@ -44,7 +44,7 @@ Check out our latest offer on https://acme.com and use your discount code today! Your marketing team at ACME Inc.` - htmlBodyTemplate = `

Hi {{.Firstname}},

+ htmlBodyTemplate = `

Hi {{.Firstname}},

we are writing your to let you know that this week we have an amazing offer for you. Using the coupon code "GOMAIL" you will get a 20% discount on all our products in our online shop.

@@ -55,58 +55,73 @@ and use your discount code today!

) func main() { - // 定义我们要发送邮件的用户列表 - ul := []User{ - {"Toni", "Tester", "toni.tester@example.com"}, - {"Tina", "Tester", "tina.tester@example.com"}, - {"John", "Doe", "john.doe@example.com"}, - } - - // 准备不同的模板 - ttpl, err := tt.New("texttpl").Parse(textBodyTemplate) - if err != nil { - log.Fatalf("failed to parse text template: %s", err) - } - htpl, err := ht.New("htmltpl").Parse(htmlBodyTemplate) - if err != nil { - log.Fatalf("failed to parse text template: %s", err) - } - - var ms []*mail.Msg - r := rand.New(rand.NewSource(time.Now().UnixNano())) - for _, u := range ul { - rn := r.Int31() - m := mail.NewMsg() - if err := m.EnvelopeFrom(fmt.Sprintf("noreply+%d@acme.com", rn)); err != nil { - log.Fatalf("failed to set ENVELOPE FROM address: %s", err) - } - if err := m.FromFormat(senderName, senderAddr); err != nil { - log.Fatalf("failed to set formatted FROM address: %s", err) - } - if err := m.AddToFormat(fmt.Sprintf("%s %s", u.Firstname, u.Lastname), u.EmailAddr); err != nil { - log.Fatalf("failed to set formatted TO address: %s", err) - } - m.SetMessageID() - m.SetDate() - m.SetBulk() - m.Subject(fmt.Sprintf("%s, we have a great offer for you!", u.Firstname)) - if err := m.SetBodyHTMLTemplate(htpl, u); err != nil { - log.Fatalf("failed to set HTML template as HTML body: %s", err) - } - if err := m.AddAlternativeTextTemplate(ttpl, u); err != nil { - log.Fatalf("failed to set text template as alternative body: %s", err) - } - - ms = append(ms, m) - } - - // 通过SMTP发送邮件 - c, err := mail.NewClient("smtp.example.com", - mail.WithSMTPAuth(mail.SMTPAuthPlain), mail.WithTLSPolicy(mail.TLSMandatory), - mail.WithUsername(os.Getenv("SMTP_USER")), mail.WithPassword(os.Getenv("SMTP_PASS")), - ) - if err := c.DialAndSend(ms...); err != nil { - log.Fatalf("failed to deliver mail: %s", err) - } - log.Printf("Bulk mailing successfully delivered.") + // Define a list of users we want to mail to + ul := []User{ + {"Toni", "Tester", "toni.tester@example.com"}, + {"Tina", "Tester", "tina.tester@example.com"}, + {"John", "Doe", "john.doe@example.com"}, + } + + // Prepare the different templates + ttpl, err := tt.New("texttpl").Parse(textBodyTemplate) + if err != nil { + log.Fatalf("failed to parse text template: %s", err) + } + htpl, err := ht.New("htmltpl").Parse(htmlBodyTemplate) + if err != nil { + log.Fatalf("failed to parse text template: %s", err) + } + + var ms []*mail.Msg + r := rand.New(rand.NewSource(time.Now().UnixNano())) + for _, u := range ul { + rn := r.Int31() + m := mail.NewMsg() + if err := m.EnvelopeFrom(fmt.Sprintf("noreply+%d@acme.com", rn)); err != nil { + log.Fatalf("failed to set ENVELOPE FROM address: %s", err) + } + if err := m.FromFormat(senderName, senderAddr); err != nil { + log.Fatalf("failed to set formatted FROM address: %s", err) + } + if err := m.AddToFormat(fmt.Sprintf("%s %s", u.Firstname, u.Lastname), u.EmailAddr); err != nil { + log.Fatalf("failed to set formatted TO address: %s", err) + } + m.SetMessageID() + m.SetDate() + m.SetBulk() + m.Subject(fmt.Sprintf("%s, we have a great offer for you!", u.Firstname)) + if err := m.SetBodyHTMLTemplate(htpl, u); err != nil { + log.Fatalf("failed to set HTML template as HTML body: %s", err) + } + if err := m.AddAlternativeTextTemplate(ttpl, u); err != nil { + log.Fatalf("failed to set text template as alternative body: %s", err) + } + + ms = append(ms, m) + } + + // Deliver the mails via SMTP + c, err := mail.NewClient("smtp.example.com", + mail.WithSMTPAuth(mail.SMTPAuthPlain), mail.WithTLSPolicy(mail.TLSMandatory), + mail.WithUsername(os.Getenv("SMTP_USER")), mail.WithPassword(os.Getenv("SMTP_PASS")), + ) + if err := c.DialAndSend(ms...); err != nil { + log.Fatalf("failed to deliver mail: %s", err) + } + log.Printf("Bulk mailing successfully delivered.") } +``` + +Let's take the example apart to look at some details... + +At first, in [line 15](#hl-0-15), we define a new type for our users that we want to address. This is totally optional and is only done so we can easily work with a list of users and address them later on in our text template. How you handle this, is totally up to you and not mandatory for this to work. + +In [line 28](#hl-0-28) thru [48](#hl-0-48) we set up a simple text and HTML template mail body with placeholders that can be used with Go's `html/template` and `text/template`. + +Next we set up a list of users, we want to send our great bulk mailing to. [Line 52](#hl-0-52) uses the `User` type for this. With the preparation work done, we will start looping over all of our users in [line 70](#hl-0-70). For each user we create a new `*mail.Msg`. + +For bulk mailings it is common that the `ENVELOPE FROM` and the `MAIL FROM` differ, so that bounce mails are sent to some system that can mark those bounces in the local system as bounced. Therefore we set both of those from addresses in [line 73](#hl-0-73) and [line 76](#hl-0-76). The lines [79](#hl-0-79) to [85](#hl-0-85) should be of no surprise to you, if you already used go-mail before. + +One more interesting thing happens in [lines 86](#hl-0-86) thru [91](#hl-0-91) in which we use our prepared `html/template` and `text/template` templates and apply it to our mail message using `m.SetBodyHTMLTemplate` and `m.AddAlternativeTextTemplate`. We provide the whole user struct as data to that methods, so that `html/template` and `text/template` can take care of replacing placeholders in the mail body. Go-mail will take care of all the bells and whistles with the template handling for you. With our mail message now complete, we append it to our mail message slice in [line 93](#hl-0-93). + +Finally we create a new [Client](/reference/client/) and send out all of our prepared messages in one go by providing the whole slice of messages to `Client.DialAndSend`. \ No newline at end of file From 609dba28fb2a0798bd5a39cff23d8bc10a842acd Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:26:33 +0100 Subject: [PATCH 10/25] New translations security.md (Chinese Simplified) --- content/zh/security.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/content/zh/security.md b/content/zh/security.md index ca5c0cc..1ac74fa 100644 --- a/content/zh/security.md +++ b/content/zh/security.md @@ -1,21 +1,21 @@ --- -title: 安全策略 +title: Security policy --- -## 已知漏洞 +## Known vulnerabilities -尽管 go-mail 没有已知的安全漏洞,您仍然可以查看我们的 GitHub 项目的[安全公告](https://github.com/wneessen/go-mail/security/advisories)页面。 +Even though there is no known security vulnerability in go-mail, you can always check the [security advisories](https://github.com/wneessen/go-mail/security/advisories) page of our GitHub project. -## 报告漏洞 +## Reporting a Vulnerability -要报告 go-mail 中的(可能的)安全问题,请发送电子邮件至[security@go-mail.dev](mailto:security@go-mail.dev)或使用 Github 的[私人报告功能](https://github.com/wneessen/go-mail/security/advisories/new)。我们非常欢迎报告。即使您不确定您发现的特定问题是否属于安全问题,我们也很乐意听取详细信息,以便我们一起确定是否需要解决该问题。 +To report (possible) security issues in go-mail, please either send a mail to [security@go-mail.dev](mailto:security@go-mail.dev) or use Github's [private reporting feature](https://github.com/wneessen/go-mail/security/advisories/new). Reports are always welcome. Even if you are not 100% certain that a specific issue you found counts as a security issue, we'd love to hear the details, so we can figure out together if the issue in question needds to be addressed. -通常,您会在一天内甚至几个小时内收到答复。 +Typically, you will receive an answer within a day or even within a few hours. -### 端到端加密 -您可以将 OpenPGP/GPG 加密邮件发送到[security@go-mail.dev](mailto:security@go-mail.dev)地址。 +### End-to-End encryption +You can send OpenPGP/GPG encrpyted mails to the [security@go-mail.dev](mailto:security@go-mail.dev) address. -OpenPGP/GPG 公钥: +OpenPGP/GPG public key: ``` -----BEGIN PGP PUBLIC KEY BLOCK----- xjMEY8RwPBYJKwYBBAHaRw8BAQdAiLsW7pv+CCMq5Ol0hbIB1HnJI97u3zJw @@ -29,4 +29,4 @@ TBOxf8keAAIbDBYhBAoWEB7Y0bE7zcIOuaBME7F/yR4AAADaMwD9EvEA3NSN NtdSaeL/euh6oRRiCjKzh5bIqZiQXqMlIOoBAJvPE2facs8MISwTtDoHW0sD WdOs3yBpGlGCs5WEqvQH=zn96 -----END PGP PUBLIC KEY BLOCK----- -``` +``` \ No newline at end of file From 9023b11ea1b4fc2cb9e58465671399437eeed2fc Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:31:22 +0100 Subject: [PATCH 11/25] New translations _index.md (Chinese Simplified) --- content/zh/_index.md | 82 ++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/content/zh/_index.md b/content/zh/_index.md index b2cc868..54970bf 100644 --- a/content/zh/_index.md +++ b/content/zh/_index.md @@ -1,142 +1,142 @@ --- -title: Welcome to the go-mail documentation +title: 欢迎使用 go-mail 文档 geekdocNav: false #geekdocAlign: center geekdocAnchor: false --- -[![GoDoc](https://godoc.org/github.com/wneessen/go-mail?status.svg)](https://pkg.go.dev/github.com/wneessen/go-mail) [![codecov](https://codecov.io/gh/wneessen/go-mail/branch/main/graph/badge.svg?token=37KWJV03MR)](https://codecov.io/gh/wneessen/go-mail) [![Go Report Card](https://goreportcard.com/badge/github.com/wneessen/go-mail)](https://goreportcard.com/report/github.com/wneessen/go-mail) [![Crowdin](https://badges.crowdin.net/go-mail/localized.svg)](https://crowdin.com/project/go-mail) [![GitHub release](https://img.shields.io/github/v/release/wneessen/go-mail)](https://github.com/wneessen/go-mail/releases/latest) [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go) [![#go-mail on Discord](https://img.shields.io/badge/Discord-%23gomail-blue.svg)](https://discord.gg/dbfQyC4s) [![REUSE status](https://api.reuse.software/badge/github.com/wneessen/go-mail)](https://api.reuse.software/info/github.com/wneessen/go-mail) +[![GoDoc](https://godoc.org/github.com/wneessen/go-mail?status.svg)](https://pkg.go.dev/github.com/wneessen/go-mail) [![codecov](https://codecov.io/gh/wneessen/go-mail/branch/main/graph/badge.svg?token=37KWJV03MR)](https://codecov.io/gh/wneessen/go-mail) [![Go Report Card](https://goreportcard.com/badge/github.com/wneessen/go-mail)](https://goreportcard.com/report/github.com/wneessen/go-mail) [![Crowdin](https://badges.crowdin.net/go-mail/localized.svg)](https://crowdin.com/project/go-mail) [![GitHub release](https://img.shields.io/github/v/release/wneessen/go-mail)](https://github.com/wneessen/go-mail/releases/latest) [![在 Awesome Go 中提到](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go) [![#go-mail on Discord](https://img.shields.io/badge/Discord-%23gomail-blue.svg)](https://discord.gg/dbfQyC4s) [![REUSE status](https://api.reuse.software/badge/github.com/wneessen/go-mail)](https://api.reuse.software/info/github.com/wneessen/go-mail) Mastodon Follow buy ma a coffee

go-mail logo

-go-mail is an easy to use Go library for formating and sending mails. It uses idiomatic Go style and follows best practice with sane defaults. The library only dependends on the Go Standard Library. +go-mail 是一个易于使用的 Go 库,用于格式化和发送邮件。 它使用惯用的 Go 风格,并遵循最佳实践和合理的默认值。 该库仅依赖于 Go 标准库。 -go-mail works like a programatic email client and provides lots of methods and functionalities you would consider standard in a MUA. +go-mail 的工作方式类似于编程式电子邮件客户端,并提供了许多您在 MUA 中考虑的标准方法和功能。
-{{< button size="huge" relref="getting-started/introduction/" >}}Get started using go-mail{{< /button >}} +{{< button size="huge" relref="getting-started/introduction/" >}}开始使用 go-mail{{< /button >}}
-## Feature highlights +## 特色亮点 {{< columns >}} ### Standard Library dependant -go-mail does not require any third-party modules and only runs on the Go standard library +go-mail 不需要任何第三方模块,仅运行在 Go 标准库上 <---> -### Modern, idiomatic Go +### 现代、惯用的 Go -We are using modern and idiotmatic Go standards with this library and follow state-of-the-art best practices with sane defaults +我们使用现代和惯用的 Go 标准,遵循最先进的最佳实践和合理的默认值 <---> -### Full TLS support +### 完整的 TLS 支持 -go-mail supports implicit STARTTLS with different policies as well as explicit SSL/TLS for connections to sending mail servers +go-mail 支持不同策略的隐式 STARTTLS,以及用于发送邮件服务器的显式 SSL/TLS 的连接 {{< /columns >}} {{< columns >}} -### Contexts +### 上下文 -We make use of Go contexts for better control flow and timeout/cancelation handling +我们利用 Go 上下文进行更好的控制流和超时/取消处理 <---> -### SMTP Authentication +### SMTP 认证 -Support for three common SMTP authentication mechanisms (LOGIN, PLAIN, CRAM-MD5) as well as custom authentications. +支持三种常见的 SMTP 认证机制(LOGIN、PLAIN、CRAM-MD5)以及自定义身份验证。 <---> -### Mail address validation +### 邮件地址验证 -go-mail follows RFC5322 and validates the provided mail addresses +go-mail 遵循 RFC5322 并验证提供的邮件地址 {{< /columns >}} {{< columns >}} -### Common mail header support +### 常见邮件头支持 -go-mail brings generators for lots of common mail headers (Message-ID, Date, Bulk-Precedence, Priority, etc.) +go-mail 提供了许多常见邮件头的生成器(Message-ID、Date、Bulk-Precedence、Priority 等) <---> -### Connection reusing +### 连接重用 -You can send mulitple mails over the same SMTP connection +您可以在同一 SMTP 连接上发送多个邮件 <---> -### Attachments/Embeds +### 附件/嵌入 -Full support for attachments and inline embeds from different sources (local file system, `io.Reader` or `embed.FS`) +来自不同来源(本地文件系统、`io.Reader` 或 `embed.FS`)的附件和内联嵌入的完全支持 {{< /columns >}} {{< columns >}} -### Encodings and content types +### 编码和内容类型 -go-mail supports different encondings and content types out of the box +go-mail 支持不同的编码和内容类型 <---> -### Middlewares +### 中间件 -Middleware support for 3rd-party libraries to alter mail message to their need +第三方库的中间件支持,以便更改邮件消息以满足其需求 <---> -### Sendmail and file storage +### Sendmail 和文件存储 -Support for sending mail messages through a local sendmail installation as well as output to local files (e. g. as `.eml` files to disk to open them in a MUA) +支持通过本地 sendmail 安装发送邮件消息以及输出到本地文件(例如作为磁盘上的 `.eml` 文件以在 MUA 中打开它们) as `.eml` files to disk to open them in a MUA) {{< /columns >}} {{< columns >}} -### MDNs and DSNs +### MDN 和 DSN -go-mail brings support for requestng MDNs (RFC 8098) and DSNs (RFC 1891) +go-mail 提供了请求 MDN(RFC 8098)和 DSN(RFC 1891)的支持 <---> -### Template support +### 模板支持 -Support for Go's `html/template` and `text/template` (as message body, alternative part or attachment/emebed) +支持 Go 的 `html/template` 和 `text/template`(作为消息正文、替代部分或附件/嵌入) <---> -### DKIM support +### DKIM 支持 -DKIM signature support via the [go-mail-middlware/dkim](https://github.com/wneessen/go-mail-middleware/tree/main/dkim) middleware +通过 [go-mail-middlware/dkim](https://github.com/wneessen/go-mail-middleware/tree/main/dkim) 中间件的 DKIM 签名支持 {{< /columns >}} {{< columns >}} -### Debug logging +### 调试日志记录 -Support for the SMTP client to log any SMTP communication to STDERR for debug purposes +支持 SMTP 客户端将任何 SMTP 通信记录到 STDERR 以进行调试目的 <---> -### Custom delivery errors +### 自定义交付错误 -With the `SendError` type the user is able to get detailed information about delivery errors including if the error is of temporary nature or not +使用 `SendError` 类型,用户可以获取有关交付错误的详细信息,包括错误是否为临时性质 <---> {{< /columns >}} -## Support -We have a support and general discussion channel on Discord. Find us at: [#go-mail](https://discord.gg/dbfQyC4s) +## 支持 +我们在 Discord 上有一个支持和一般讨论频道。 找到我们:[#go-mail](https://discord.gg/dbfQyC4s) From 645a942249f23b6130a4ec82efa3710837f8ddca Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:31:24 +0100 Subject: [PATCH 12/25] New translations guide.md (Chinese Simplified) --- content/zh/community/guide.md | 124 +++++++++++++++++----------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/content/zh/community/guide.md b/content/zh/community/guide.md index 3cff368..f165fb8 100644 --- a/content/zh/community/guide.md +++ b/content/zh/community/guide.md @@ -1,109 +1,109 @@ --- -title: Community Guide +title: 社区指南 --- -The go-mail community is growing and if you're reading this, chances are that you want to join, too! +go-mail社区正在壮大,如果您正在阅读此文,那么您也想加入! {{< toc >}} -## Resources +## 资源 -### Code of Conduct +### 行为准则 -In our community, we follow our [Code of Conduct](https://github.com/wneessen/go-mail/blob/main/CODE_OF_CONDUCT.md) and ask everybody who likes to participate to act accordingly. +在我们的社区中,我们遵循我们的[行为准则](https://github.com/wneessen/go-mail/blob/main/CODE_OF_CONDUCT.md),并要求每个想要参与的人都要相应地行事。 -### Support- and annoucement channels +### 支持和公告渠道 -* [Mastodon](https://s.pebcak.de/@go_mail/): Follow us on Mastodon to receive recent news about go-mail -* [go-mail forum](https://github.com/wneessen/go-mail/discussions): Receive announcements and start discussions about go-mail. -* [Github issues](https://github.com/wneessen/go-mail/issues): If you have a bug to report or feature to request, please use GitHub issues. Please respect the rules specified in each repository's issue template. -* [Discord](https://discord.gg/dbfQyC4s): A place for go-mail devs and users to meet and chat in real time. +* [Mastodon](https://s.pebcak.de/@go_mail/):在Mastodon上关注我们,以获取有关go-mail的最新消息 +* [go-mail论坛](https://github.com/wneessen/go-mail/discussions):接收有关go-mail的公告并开始讨论。 +* [Github问题](https://github.com/wneessen/go-mail/issues):如果您要报告错误或请求功能,请使用GitHub问题。 请遵守每个存储库的问题模板中指定的规则。 +* [Discord](https://discord.gg/dbfQyC4s):go-mail开发人员和用户在此处实时会面和聊天的地方。 -## Contributing +## 贡献 -go-mail is an open source, community driven project. We welcome anyone to join us in contributing to the project. This documentation is aimed at anyone wishing to get familiar with the project and the development processes. +go-mail是一个开源的、社区驱动的项目。 我们欢迎任何人加入我们为项目做出贡献。 本文档旨在帮助任何希望熟悉项目和开发流程的人。 -* [Developing new features](#developing-new-features) -* [Fixing bugs](#fixing-bugs) -* [Testing](#testing) -* [Documenation](#documentation) -* [Translation](#translation) -* [Support](#support) +* [开发新功能](#developing-new-features) +* [修复错误](#fixing-bugs) +* [测试](#testing) +* [文档](#documentation) +* [翻译](#translation) +* [支持](#support) -### Developing New Features +### 开发新功能 -We are always keen to add features to go-mail. The process for adding new features are as follows: +我们始终热衷于为go-mail添加新功能。 添加新功能的过程如下: -* Check the [issue section on Github](https://github.com/wneessen/go-mail/issues) for available issues with the "TODO" or "help wanted" tag -* If no open "TODO"/"help wanted" issue is found or the feature you have in mind is not covered, please open a proposal issue for that specific feature and wait for the "OK" from the project maintainers -* Before developing, check that the issue includes the following information: - * The purpose of the enhancement - * What is out of scope for the enhancement -* If the issue does not include this information, feel free to request the information from the person who opened the issue. Sometimes placeholder issues are created and require more details -* Comment on the issue stating if you wish to develop the feature -* Clone the repository and create a branch with the format `feature/_` -* New features often require documentation so please ensure you have also added or updated the documentation as part of the changes -* Please make sure that your code has the required test coverage -* Once the feature is ready for testing, create a draft PR. Please ensure the PR description has the test scenarios and test cases listed with checkmarks, so that others can know what still needs to be tested -* Once all the testing is completed, please update the status of the PR from draft and leave a message +* 在Github的[问题部分](https://github.com/wneessen/go-mail/issues)中检查带有“TODO”或“help wanted”标签的可用问题 +* 如果没有找到打开的“TODO”/“help wanted”问题或您想要的功能未涵盖,请为该特定功能打开一个提案问题,并等待项目维护者的“OK” +* 开发之前,请检查问题是否包括以下信息: + * 增强的目的 + * 增强范围之外的内容 +* 如果问题不包括此信息,请随时向打开问题的人请求信息。 有时会创建占位符问题并需要更多详细信息 +* 在问题上发表评论,说明您希望开发该功能 +* 克隆存储库并创建格式为`feature/_`的分支 +* 新功能通常需要文档,因此请确保您还添加或更新了文档作为更改的一部分 +* 请确保您的代码具有所需的测试覆盖范围 +* 一旦功能准备好进行测试,请创建草案PR。 请确保PR说明中列出了测试场景和测试用例,并带有复选框,以便其他人知道仍需测试什么 +* 一旦所有测试都完成,请从草案中更新PR的状态并留言 {{< hint type=important >}} -Any PRs opened without a corresponding issue may be rejected. +未附带相应问题的任何PR可能会被拒绝。 {{< /hint >}} -### Fixing bugs +### 修复错误 -The process for fixing bugs are as follows: +修复错误的过程如下: -* Check the [Github issues](https://github.com/wneessen/go-mail/issues) and select a bug to fix -* Before developing, check that the issue includes the following information: - * The scope of the issue including platforms affected - * The steps to reproduce. Sometimes bugs are opened that are not go-mail issues and the onus is on the reporter to prove that it is a go-mail issue with a minimal reproducible example -* If the issue does not include this information, feel free to request the information from the person who opened the issue -* Comment on the issue stating you wish to develop a fix -* Clone the repository and create a branch with the format `bugfix/_` -* Once the fix is ready for testing, create a draft PR. Please ensure the PR description has the test scenarios and test cases listed with checkmarks, so that others can know what still needs to be tested -* Once all the testing is completed, please update the status of the PR from draft and leave a message. +* 检查[Github问题](https://github.com/wneessen/go-mail/issues)并选择要修复的错误 +* 开发之前,请检查问题是否包括以下信息: + * 受影响的平台范围 + * 重现步骤。 有时会打开不是go-mail问题的错误,并且责任在于报告人证明它是具有最小可重现示例的go-mail问题 +* 如果问题不包括此信息,请随时向打开问题的人请求信息 +* 在问题上发表评论,说明您希望开发修复程序 +* 克隆存储库并创建格式为`bugfix/_`的分支 +* 一旦修复程序准备好进行测试,请创建草案PR。 请确保PR说明中列出了测试场景和测试用例,并带有复选框,以便其他人知道仍需测试什么 +* 一旦所有测试都完成,请从草案中更新PR的状态并留言。 {{< hint type=note >}} -There is nothing stopping you from opening a issue and working on it yourself, but please be aware that all bugfixes should be discussed as the approach may have unintended side effects. +没有任何阻止您打开问题并自己解决它,但请注意,所有错误修复都应该进行讨论,因为方法可能会产生意外的副作用。 {{< /hint >}} {{< hint type=important >}} -Any PRs opened without a corresponding issue may be rejected. +未附带相应问题的任何PR可能会被拒绝。 {{< /hint >}} -### Testing +### 测试 -Testing is vitally important to ensure quality in the project. There are a couple of scenarios where testing can really help the project: +测试对于确保项目质量至关重要。 有几种情况下,测试可以真正帮助项目: -* Testing if a bug is reproducible on your local system -* Testing PRs to ensure that they work correctly +* 测试是否可以在本地系统上重现错误 +* 测试PR以确保它们正常工作 -If you chose to test if someone's bug report is reproducible on your local system, then feel free to add a comment on the issue confirming this with the output of your test program. +如果您选择测试某人的错误报告是否可以在本地系统上重现,则可以在问题上添加评论,确认这一点,并附上测试程序的输出。 -To test PRs, choose a PR to test and check if the PR description has the testing scenarios listed. If not, please ask the person who opened the PR to provide that list. Once you have determined a valid test scenario, please report your findings on the PR. +要测试PR,请选择要测试的PR并检查PR说明中是否列出了测试场景。 如果没有,请要求打开PR的人提供该列表。 一旦确定了有效的测试场景,请在PR上报告您的发现。 -If you ever need more clarity or help on testing, please ask a question in the [Github forum](https://github.com/wneessen/go-mail/discussions) or on [Discord](https://discord.gg/dbfQyC4s). +如果您需要更多的明确或帮助进行测试,请在[Github论坛](https://github.com/wneessen/go-mail/discussions)或[Discord](https://discord.gg/dbfQyC4s)上提问。 -### Documentation +### 文档 -While we require proper GoDoc documenation comments in the code, this website is meant as more in-depth documenation of features and the project itself. +虽然我们要求代码中有适当的GoDoc文档注释,但本网站旨在更深入地记录功能和项目本身的文档。 -Since documenattion is hard and the website is still in an incomplete state, any contribution to this is greatly appreciated. Features without documentation are condidered "unfinished" to the project, it's as important as the code. +由于文档很难,网站仍处于不完整状态,因此对此的任何贡献都将不胜感激。 没有文档的功能被认为是“未完成”的项目,它与代码一样重要。 -The website is built on Hugo using the Geekdocs theme. It's very simple and basically consists of markdown files. There are instructions on how to install the website on your local computer in the [website's repository](https://github.com/wneessen/go-mail-website). +该网站基于Hugo使用Geekdocs主题构建。 它非常简单,基本上由Markdown文件组成。 在[网站的存储库](https://github.com/wneessen/go-mail-website)中有有关如何在本地计算机上安装网站的说明。 -### Translation +### 翻译 -The default documents of the go-mail project are English documents. We use the "Crowdin" tool to translate documents in other languages and synchronize them to the website. You can [join our project](https://translations.go-mail.dev) and submit your translations to make contributions. +go-mail项目的默认文档是英文文档。 我们使用“Crowdin”工具将其他语言的文档翻译并同步到网站上。 您可以[加入我们的项目](https://translations.go-mail.dev)并提交您的翻译以进行贡献。 -Currently the only supported 2nd language is German, but we are keen to add other languages as well. Please request them via a Github issue in the go-mail-website repository. +目前,唯一支持的第二种语言是德语,但我们也热衷于添加其他语言。 请通过go-mail-website存储库中的Github问题请求它们。 -### Support +### 支持 -A great way to contribute to the project is to help others who are experiencing difficulty. This is normally reported as a issue or a message on the `#go-mail` [Discord channel](https://discord.gg/dbfQyC4s). Even just clarifying the issue can really help out. Sometimes, when an issue is discussed and gets resolved, we create a guide out of it to help others who face the same issues. +为项目做出贡献的一个很好的方法是帮助那些遇到困难的人。 这通常报告为问题或在`#go-mail` [Discord频道](https://discord.gg/dbfQyC4s)上的消息。 即使只是澄清问题,也可以真正帮助。 有时,当问题得到讨论并得到解决时,我们会将其制作成指南,以帮助其他面临相同问题的人。 From a37b16f0589fe294546f93c3cbbc0972ffc01de9 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:31:26 +0100 Subject: [PATCH 13/25] New translations introduction.md (Chinese Simplified) --- content/zh/getting-started/introduction.md | 62 ++++++++++++---------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/content/zh/getting-started/introduction.md b/content/zh/getting-started/introduction.md index 566cc34..5fa412e 100644 --- a/content/zh/getting-started/introduction.md +++ b/content/zh/getting-started/introduction.md @@ -1,35 +1,35 @@ --- -title: Introduction +title: 简介 weight: -20 --- -This short tutorial shows you how to get up and running with go-mail from installation to sending your first mail. +这篇简短的教程向您展示了如何从安装到发送第一封邮件使用go-mail。 {{< toc >}} -## Requirements +## 要求 -go-mail requires a working Go installation (Version 1.16+). Download Go from the [Go Downloads Page](https://go.dev/dl/). +go-mail需要一个工作的Go安装(版本1.16+)。 从[Go下载页面](https://go.dev/dl/)下载Go。 -## Installation +## 安装 -go-mail can be installed using the Go module installation mechanism via the `go get` command. +可以使用Go模块安装机制通过`go get`命令安装go-mail。 -To install the latest version of go-mail, enter your project folder and simply import the module by issuing the following command: +要安装go-mail的最新版本,请进入您的项目文件夹,然后通过发出以下命令导入模块即可: ```shell $ go get github.com/wneessen/go-mail ``` -## Sending your first mail +## 发送您的第一封邮件 -go-mail consists of two main components. The `Msg` which represents the mail message and the `Client` which takes care of the mail delivery via a SMTP service. +go-mail由两个主要组件组成。 `Msg`表示邮件消息,`Client`通过SMTP服务处理邮件传递。 -### Create a new message +### 创建新消息 -First let's create a new `Msg` using the `NewMsg()` method and assign a sender address as well as a recipient address. +首先,让我们使用`NewMsg()`方法创建一个新的`Msg`,并分配一个发件人地址和一个收件人地址。 ```go package main @@ -50,20 +50,20 @@ func main() { } ``` -In this little code snippet, first and foremost we import go-mail into our project. See the `import` statement in [line 4](#hl-1-4). Next we create a new message in [line 9](#hl-1-9). Lines [10](#hl-1-10) and [13](#hl-1-13) set the sender and recipient addresses. Since go-mail makes sure that you are providing valid mail addresses, we return an `error`. This way we can make sure that the provided address is accepted by go-mail and will not cause problems later on. +在这个小代码片段中,首先我们将go-mail导入我们的项目。 请参见[第4行](#hl-1-4)中的`import`语句。 接下来,我们在[第9行](#hl-1-9)中创建了一个新消息。 第[10](#hl-1-10)和[13](#hl-1-13)行设置了发件人和收件人地址。 由于go-mail确保您提供的是有效的邮件地址,因此我们返回一个`error`。 这样我们就可以确保go-mail接受提供的地址,并且不会在以后引起问题。 -Next we want to set a subject line for our message and fill the mail body with some content. +接下来,我们要为我们的邮件设置一个主题行,并填充邮件正文内容。 ```go m.Subject("This is my first mail with go-mail!") m.SetBodyString(mail.TypeTextPlain, "Do you like this mail? I certainly do!") ``` -The first argument for `SetBodyString()` is a content type we need to provide. In our example the `mail.TypeTextPlain` basically represents a `text/plain` content type - meaning a plain text mail body. +`SetBodyString()`的第一个参数是我们需要提供的内容类型。 在我们的示例中,`mail.TypeTextPlain`基本上表示`text/plain`内容类型-表示纯文本邮件正文。 -### Sending the mail +### 发送邮件 -Now that we have our mail message ready to go, let's bring it on the way and send it out. For this we'll use the `Client`, which handles the SMTP transmission. +现在我们已经准备好发送邮件消息了,让我们将其发送出去。 为此,我们将使用`Client`,它处理SMTP传输。 ```go c, err := mail.NewClient("smtp.example.com", mail.WithPort(25), mail.WithSMTPAuth(mail.SMTPAuthPlain), @@ -73,9 +73,9 @@ if err != nil { } ``` -In this example we connect to the mail server with the hostname `smtp.example.com` and provide the `Client` with a couple of options like the port we want to connect to, the fact that we want to use `SMTP PLAIN` for authentication and the username and password. +在此示例中,我们使用主机名`smtp.example.com`连接到邮件服务器,并为`Client`提供了一些选项,例如我们要连接的端口,我们要使用`SMTP PLAIN`进行身份验证以及用户名和密码。 -Finally we tell the client to deliver the mail. +最后,我们告诉客户端交付邮件。 ```go if err := c.DialAndSend(m); err != nil { @@ -83,22 +83,15 @@ if err := c.DialAndSend(m); err != nil { } ``` -The `DialAndSend()` method takes care of establishing the connection and sending out the mail. You have the option to call them separately as well, but we won't need this for the quick example. +`DialAndSend()`方法负责建立连接并发送邮件。 您也可以分别调用它们,但是我们不需要快速示例。 -## Conclusion +## 结论 -That was quite simple, wasn't it? You successfully prepared a mail message and delivered it to the recipient via a 3rd party mail server. go-mail of course can do much more. Check out the in-depth documentation for all the features. +那很简单,不是吗? 您成功地准备了一封邮件消息,并通过第三方邮件服务器将其发送给收件人。 当然,go-mail可以做更多。 查看详细文档以获取所有功能。 -## Full example code +## 完整示例代码 ```go -package main - -import ( - "github.com/wneessen/go-mail" - "log" -) - func main() { m := mail.NewMsg() if err := m.From("toni.sender@example.com"); err != nil { @@ -117,5 +110,16 @@ func main() { if err := c.DialAndSend(m); err != nil { log.Fatalf("failed to send mail: %s", err) } +} + m.Subject("This is my first mail with go-mail!") +m.SetBodyString(mail.TypeTextPlain, "Do you like this mail? I certainly do!") I certainly do!") + c, err := mail.NewClient("smtp.example.com", mail.WithPort(25), mail.WithSMTPAuth(mail.SMTPAuthPlain), + mail.WithUsername("my_username"), mail.WithPassword("extremely_secret_pass")) + if err != nil { + log.Fatalf("failed to create mail client: %s", err) + } + if err := c.DialAndSend(m); err != nil { + log.Fatalf("failed to send mail: %s", err) + } } ``` \ No newline at end of file From f7df0324b152cf241cddab5565fbde888c517e56 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:31:28 +0100 Subject: [PATCH 14/25] New translations _index.md (Chinese Simplified) --- content/zh/reference/client/_index.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/content/zh/reference/client/_index.md b/content/zh/reference/client/_index.md index 7006431..3199932 100644 --- a/content/zh/reference/client/_index.md +++ b/content/zh/reference/client/_index.md @@ -1,8 +1,8 @@ --- -title: The mail delivery client +title: 邮件发送客户端 --- -In go-mail the `Client` is responsible for the mail delivery with remote mail servers that communicate via the SMTP protocol. +在 go-mail 中,`Client` 负责通过 SMTP 协议与远程邮件服务器进行邮件传递。 {{< toc >}} @@ -34,9 +34,9 @@ func main() { {{< /tab >}} {{< /tabs >}} -To create a new `Client`, you can use the `NewClient()` method. As first argument it requires the hostname of the sending SMTP server. Optionally you can provide a list of `Option` funcionts. These option functions can be used to override the default settings of the `Client`. +要创建新的 `Client`,您可以使用 `NewClient()` 方法。 作为第一个参数,它需要发送 SMTP 服务器的主机名。 您可以选择提供一系列 `Option` 函数。 这些选项函数可用于覆盖 `Client` 的默认设置。 -Check the [Options](options) documentation for in-depth details to all available Options. +有关所有可用选项的详细信息,请查看 [Options](options) 文档。 ## Client @@ -45,7 +45,7 @@ Check the [Options](options) documentation for in-depth details to all available ```go type Client struct { -// contains filtered or unexported fields +// 包含过滤或未导出字段 } ``` @@ -81,7 +81,7 @@ func main() { {{< /tab >}} {{< /tabs >}} -`Close()` closes the connection to the SMTP server the `Client` is connected to. It returns an `error` in case the `Client` has no active connection or if closing the connection fails. +`Close()` 关闭 `Client` 连接到的 SMTP 服务器的连接。 如果 `Client` 没有活动连接或关闭连接失败,则返回 `error`。 ### DialAndSend() @@ -127,7 +127,7 @@ func main() { {{< /tab >}} {{< /tabs >}} -The `DialAndSend()` method is an alias for [DialAndSendWithContext()](#dialandsendwithcontext) with a default `context.Background` context. `DialAndSend()` takes a list of `Msg` pointer as argument(s) and returns an `error` in case any of the performed actions fails. +`DialAndSend()` 方法是 [DialAndSendWithContext()](#dialandsendwithcontext) 的别名,使用默认的 `context.Background` 上下文。 `DialAndSend()` 接受一个或多个 `Msg` 指针作为参数,并在执行任何操作失败时返回 `error`。 ### DialAndSendWithContext() @@ -174,6 +174,6 @@ func main() { {{< /tab >}} {{< /tabs >}} -The `DialAndSendWithContext()` is a one-for-all shortcut method on the `Client`. Once the `Client` is created, calling the `DialAndSendWithContext()` method will have it connect to the configured server, send out the given mail `Msg` and finalize by closing the connection again. +`DialAndSendWithContext()` 是 `Client` 上的一站式快捷方法。 一旦创建了 `Client`,调用 `DialAndSendWithContext()` 方法将使其连接到配置的服务器,发送给定的邮件 `Msg`,然后通过再次关闭连接来完成。 -The first argument of the method is a `context.Context` followed by a list of one or more `Msg` pointers. `DialAndSendWithContext()` does return an `error` in case any of the performed actions fails. \ No newline at end of file +该方法的第一个参数是 `context.Context`,后跟一个或多个 `Msg` 指针。 `DialAndSendWithContext()` 在执行任何操作失败时返回 `error`。 \ No newline at end of file From 074d51e415498de22a17d68e6ac5dbeda78ea0a0 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:31:30 +0100 Subject: [PATCH 15/25] New translations options.md (Chinese Simplified) --- content/zh/reference/client/options.md | 55 +++++++++++++------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/content/zh/reference/client/options.md b/content/zh/reference/client/options.md index b237fd5..58a0a7d 100644 --- a/content/zh/reference/client/options.md +++ b/content/zh/reference/client/options.md @@ -1,5 +1,5 @@ --- -title: Client options +title: 客户端选项 --- {{< toc >}} @@ -14,7 +14,7 @@ type Option func(*Client) error {{< /tab >}} {{< /tabs >}} -Client `Option` are functions that can be used as optional arguments for the `NewClient()` methods to override the default vaules of the returned `Client`. +`Option` 是可选参数函数,可以用作 `NewClient()` 方法的可选参数,以覆盖返回的 `Client` 的默认值。 ### WithDebugLog() {{< tabs "WithDebugLog" >}} @@ -42,11 +42,11 @@ Introduced in [go-mail v0.3.9](https://github.com/wneessen/go-mail/releases/tag/ {{< /tab >}} {{< /tabs >}} -`WithDebugLog` enables debug logging of SMTP traffic on the `Client`. When enabled, any SMTP communication from the client to the server and vice-versa is logged to `os.Stderr`. +`WithDebugLog` 启用 SMTP 流量的调试日志。 启用后,客户端与服务器之间的任何 SMTP 通信都会记录到 `os.Stderr`。 -In the output `C --> S` is the communication from the client to the server and `C <-- S` represents the communication back from the server to the client. +在输出中,`C --> S` 是客户端到服务器的通信,`C <-- S` 表示服务器到客户端的通信。 -Here is an output example: +以下是输出示例: ``` 2023/01/15 20:21:18 [DEBUG] C --> S: EHLO client.example.com 2023/01/15 20:21:18 [DEBUG] C <-- S: 250 server.example.com @@ -101,16 +101,16 @@ func main() { {{< /tab >}} {{< /tabs >}} -The `WithDSN` option function tells the `Client` to request DSNs (if the server supports it) as described in [RFC 1891](https://rfc-editor.org/rfc/rfc1891.html). +`WithDSN` 选项函数告诉 `Client` 请求 DSN(如果服务器支持)如[RFC 1891](https://rfc-editor.org/rfc/rfc1891.html)所述。 -DSNs (Delivery Status Notification) are an extension to the SMTP protocol and need to be supported by the sending server. The RFC for DSNs defines different parameters of which we've implemented the once which we think make most sense for go-mail: +DSN(传递状态通知)是 SMTP 协议的扩展,需要发送服务器支持。 DSN 的 RFC 定义了不同的参数,我们已经实现了我们认为对 go-mail 最有意义的参数: -* The `RET` extension for the `MAIL FROM` command, to let the user specify if a DSN should contain the full mail (`FULL`) or only headers (`HDRS`) of the sent mail. -* The `NOTIFY` extension that allows the user to request a DSN for the different types of allowed situations: `NEVER`, `SUCCESS`, `FAILURE` and `DELAY` +* `MAIL FROM` 命令的 `RET` 扩展,让用户指定 DSN 是否应包含发送邮件的全部内容(`FULL`)或仅包含邮件头(`HDRS`)。 +* `NOTIFY` 扩展允许用户为不同类型的允许情况请求 DSN:`NEVER`、`SUCCESS`、`FAILURE` 和 `DELAY` -`ENVID` and `ORCPT` are currently not supported but might follow in a later relaese (please open an [issue](https://github.com/wneessen/go-mail/issues/new/choose) if you see usefulness in this). +`ENVID` 和 `ORCPT` 目前不受支持,但可能会在以后的版本中跟进(如果您认为这很有用,请打开一个 [issue](https://github.com/wneessen/go-mail/issues/new/choose))。 -By default `WithDSN()` sets the `FULL` *Mail From Return Option* and the `SUCCESS` and `FAILURE` *Recipient Notify Options*. If you like to use other settings for the DSN, please see the documentation for [WithDSNMailReturnType](#withdsnmailreturntype) and [WithDSNRcptNotifyType](#withdsnrcptnotifytype) +默认情况下,`WithDSN()` 设置 `FULL` 的 *Mail From Return Option* 和 `SUCCESS` 和 `FAILURE` 的 *Recipient Notify Options*。 如果您想使用其他 DSN 设置,请参阅 [WithDSNMailReturnType](#withdsnmailreturntype) 和 [WithDSNRcptNotifyType](#withdsnrcptnotifytype) 的文档。 ### WithDSNMailReturnType() {{< tabs "WithDSNMailReturnType" >}} @@ -135,14 +135,14 @@ func main() { {{< /tab >}} {{< /tabs >}} -`WithDSNMailReturnType` enables the `Client` to request DSNs (if the server supports it) as described in the [RFC 1891](https://www.rfc-editor.org/rfc/rfc1891) and set the `MAIL FROM` Return option type to the given `DSNMailReturnOption` +`WithDSNMailReturnType` 启用 `Client` 请求 DSN,如[RFC 1891](https://www.rfc-editor.org/rfc/rfc1891)所述,并将 `MAIL FROM` 返回选项类型设置为给定的 `DSNMailReturnOption`。 -go-mail has the following two `DSNMailReturnOption` type already built-in: +go-mail 已经内置了以下两种 `DSNMailReturnOption` 类型: -* `DSNMailReturnHeadersOnly`: requests that only the headers of the message be returned. \ - See: [RFC 1891, Section 5.3](https://www.rfc-editor.org/rfc/rfc1891#section-5.3) -* `DSNMailReturnFull`: requests that the entire message be returned in any "failed" delivery status notification issued for this recipient \ - See: [RFC 1891, Section 5.3](https://www.rfc-editor.org/rfc/rfc1891#section-5.3) +* `DSNMailReturnHeadersOnly`:请求仅返回邮件的头部。 \ + 参见:[RFC 1891,第5.3节](https://www.rfc-editor.org/rfc/rfc1891#section-5.3) +* `DSNMailReturnFull`:请求在为此收件人发出“失败”的传递状态通知时返回整个消息。 \ + 参见:[RFC 1891,第5.3节](https://www.rfc-editor.org/rfc/rfc1891#section-5.3) ### WithDSNRcptNotifyType() @@ -170,17 +170,18 @@ func main() { {{< /tab >}} {{< /tabs >}} -`WithDSNRcptNotifyType` enables the `Client` to request DSNs as described in [RFC 1891](https://www.rfc-editor.org/rfc/rfc1891) and sets the `RCPT TO` notify options to the given list of `DSNRcptNotifyOption` +`WithDSNRcptNotifyType` 启用 `Client` 请求 DSN,如[RFC 1891](https://rfc-editor.org/rfc/rfc1891.html)所述,并将 `RCPT TO` 通知选项设置为给定的 `DSNRcptNotifyOption` 列表。 -go-mail has the following `DSNRcptNotifyOption` types already built-in: +go-mail 已经内置了以下 `DSNRcptNotifyOption` 类型: -* `DSNRcptNotifyNever`: requests that a DSN not be returned to the sender under any conditions. \ - See: [RFC 1891, Section 5.1](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) -* `DSNRcptNotifySuccess`: requests that a DSN be issued on successful delivery \ - See: [RFC 1891, Section 5.1](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) -* `DSNRcptNotifyFailure`: requests that a DSN be issued on delivery failure \ - See: [RFC 1891, Section 5.1](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) -* `DSNRcptNotifyDelay`: indicates the sender's willingness to receive "delayed" DSNs. Delayed DSNs may be issued if delivery of a message has been delayed for an unusual amount of time (as determined by the MTA at which the message is delayed), but the final delivery status (whether successful or failure) cannot be determined. The absence of the DELAY keyword in a NOTIFY parameter requests that a "delayed" DSN NOT be issued under any conditions. See: [RFC 1891, Section 5.1](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) +* `DSNRcptNotifyNever`:不要在任何情况下向发送方返回 DSN。 \ + 参见:[RFC 1891,第5.1节](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) +* `DSNRcptNotifySuccess`:请求在成功传递时发出 DSN\ + 参见:[RFC 1891,第5.1节](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) +* `DSNRcptNotifyFailure`:请求在传递失败时发出 DSN\ + 参见:[RFC 1891,第5.1节](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) +* `DSNRcptNotifyDelay`:表示发送方愿意接收“延迟”的 DSN。 如果消息的传递已经被延迟了不寻常的时间(由消息被延迟的 MTA 确定),但无法确定最终的传递状态(无论成功还是失败),则可以发出延迟的 DSN。 在 NOTIFY 参数中缺少 DELAY 关键字会要求在任何情况下都不发出“延迟”的 DSN。 \ + 参见:[RFC 1891,第5.1节](https://www.rfc-editor.org/rfc/rfc1891#section-5.1) ### WithHELO() @@ -206,4 +207,4 @@ func main() { {{< /tab >}} {{< /tabs >}} -`WithHELO` instructs the `Client` to use the provided string as HELO/EHLO greeting host. By default the `Client` will use Go's `os.Hostname()` method to get the local hostname and use that for the HELO/EHLO greeting. `WithHELO` will override this. \ No newline at end of file +`WithHELO` 指示 `Client` 使用提供的字符串作为 HELO/EHLO 问候主机。 默认情况下,`Client` 将使用 Go 的 `os.Hostname()` 方法获取本地主机名,并将其用于 HELO/EHLO 问候。 `WithHELO` 将覆盖此设置。 \ No newline at end of file From 883c18e63c9a0ed8162b3bc0bdf52749e8b8ce1d Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:31:32 +0100 Subject: [PATCH 16/25] New translations bulk-mailer.md (Chinese Simplified) --- content/zh/examples/bulk-mailer.md | 102 ++++++++++++----------------- 1 file changed, 43 insertions(+), 59 deletions(-) diff --git a/content/zh/examples/bulk-mailer.md b/content/zh/examples/bulk-mailer.md index 105652f..50054c2 100644 --- a/content/zh/examples/bulk-mailer.md +++ b/content/zh/examples/bulk-mailer.md @@ -1,8 +1,8 @@ --- -title: Bulk Mailer Example +title: 批量邮件示例 --- -In this example we create a small bulk mailer for sending out the same mail to a bigger list of recipients. It is important for us to address the recipient directly in the mail, therefore we will make use of Go's `html/template` and `text/template` system together with placeholders. +在这个示例中,我们创建了一个小型的批量邮件发送程序,可以将相同的邮件发送给更多的收件人。 对于我们来说,重要的是直接在邮件中寻址收件人,因此我们将使用Go的`html/template`和`text/template`系统以及占位符。 ```go package main @@ -46,69 +46,53 @@ Your marketing team htmlBodyTemplate = `

Hi {{.Firstname}},

we are writing your to let you know that this week we have an amazing offer for you. -Using the coupon code "GOMAIL" you will get a 20% discount on all -our products in our online shop.

-

Check out our latest offer on https://acme.com -and use your discount code today!

-

Your marketing team
-  at ACME Inc.

` -) +// 准备不同的模板 +ttpl, err := tt.New("texttpl").Parse(textBodyTemplate) +if err != nil { + log.Fatalf("failed to parse text template: %s", err) +} +htpl, err := ht.New("htmltpl").Parse(htmlBodyTemplate) +if err != nil { + log.Fatalf("failed to parse text template: %s", err) +} -func main() { - // Define a list of users we want to mail to - ul := []User{ - {"Toni", "Tester", "toni.tester@example.com"}, - {"Tina", "Tester", "tina.tester@example.com"}, - {"John", "Doe", "john.doe@example.com"}, +var ms []*mail.Msg +r := rand.New(rand.NewSource(time.Now().UnixNano())) +for _, u := range ul { + rn := r.Int31() + m := mail.NewMsg() + if err := m.EnvelopeFrom(fmt.Sprintf("noreply+%d@acme.com", rn)); err != nil { + log.Fatalf("failed to set ENVELOPE FROM address: %s", err) } - - // Prepare the different templates - ttpl, err := tt.New("texttpl").Parse(textBodyTemplate) - if err != nil { - log.Fatalf("failed to parse text template: %s", err) + if err := m.FromFormat(senderName, senderAddr); err != nil { + log.Fatalf("failed to set formatted FROM address: %s", err) } - htpl, err := ht.New("htmltpl").Parse(htmlBodyTemplate) - if err != nil { - log.Fatalf("failed to parse text template: %s", err) + if err := m.AddToFormat(fmt.Sprintf("%s %s", u.Firstname, u.Lastname), u.EmailAddr); err != nil { + log.Fatalf("failed to set formatted TO address: %s", err) } - - var ms []*mail.Msg - r := rand.New(rand.NewSource(time.Now().UnixNano())) - for _, u := range ul { - rn := r.Int31() - m := mail.NewMsg() - if err := m.EnvelopeFrom(fmt.Sprintf("noreply+%d@acme.com", rn)); err != nil { - log.Fatalf("failed to set ENVELOPE FROM address: %s", err) - } - if err := m.FromFormat(senderName, senderAddr); err != nil { - log.Fatalf("failed to set formatted FROM address: %s", err) - } - if err := m.AddToFormat(fmt.Sprintf("%s %s", u.Firstname, u.Lastname), u.EmailAddr); err != nil { - log.Fatalf("failed to set formatted TO address: %s", err) - } - m.SetMessageID() - m.SetDate() - m.SetBulk() - m.Subject(fmt.Sprintf("%s, we have a great offer for you!", u.Firstname)) - if err := m.SetBodyHTMLTemplate(htpl, u); err != nil { - log.Fatalf("failed to set HTML template as HTML body: %s", err) - } - if err := m.AddAlternativeTextTemplate(ttpl, u); err != nil { - log.Fatalf("failed to set text template as alternative body: %s", err) - } - - ms = append(ms, m) + m.SetMessageID() + m.SetDate() + m.SetBulk() + m.Subject(fmt.Sprintf("%s, we have a great offer for you!", u.Firstname)) + if err := m.SetBodyHTMLTemplate(htpl, u); err != nil { + log.Fatalf("failed to set HTML template as HTML body: %s", err) } - - // Deliver the mails via SMTP - c, err := mail.NewClient("smtp.example.com", - mail.WithSMTPAuth(mail.SMTPAuthPlain), mail.WithTLSPolicy(mail.TLSMandatory), - mail.WithUsername(os.Getenv("SMTP_USER")), mail.WithPassword(os.Getenv("SMTP_PASS")), - ) - if err := c.DialAndSend(ms...); err != nil { - log.Fatalf("failed to deliver mail: %s", err) + if err := m.AddAlternativeTextTemplate(ttpl, u); err != nil { + log.Fatalf("failed to set text template as alternative body: %s", err) } - log.Printf("Bulk mailing successfully delivered.") + + ms = append(ms, m) +} + +// 通过SMTP发送邮件 +c, err := mail.NewClient("smtp.example.com", + mail.WithSMTPAuth(mail.SMTPAuthPlain), mail.WithTLSPolicy(mail.TLSMandatory), + mail.WithUsername(os.Getenv("SMTP_USER")), mail.WithPassword(os.Getenv("SMTP_PASS")), +) +if err := c.DialAndSend(ms...); err != nil { + log.Fatalf("failed to deliver mail: %s", err) +} +log.Printf("Bulk mailing successfully delivered.") } ``` From 18cc0012810c6f35c49c21f9424c19f89603efca Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 21 Mar 2023 15:31:34 +0100 Subject: [PATCH 17/25] New translations security.md (Chinese Simplified) --- content/zh/security.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/content/zh/security.md b/content/zh/security.md index 1ac74fa..95121bd 100644 --- a/content/zh/security.md +++ b/content/zh/security.md @@ -1,21 +1,21 @@ --- -title: Security policy +title: 安全策略 --- -## Known vulnerabilities +## 已知漏洞 -Even though there is no known security vulnerability in go-mail, you can always check the [security advisories](https://github.com/wneessen/go-mail/security/advisories) page of our GitHub project. +尽管 go-mail 没有已知的安全漏洞,您仍然可以查看我们的 GitHub 项目的[安全公告](https://github.com/wneessen/go-mail/security/advisories)页面。 -## Reporting a Vulnerability +## 报告漏洞 -To report (possible) security issues in go-mail, please either send a mail to [security@go-mail.dev](mailto:security@go-mail.dev) or use Github's [private reporting feature](https://github.com/wneessen/go-mail/security/advisories/new). Reports are always welcome. Even if you are not 100% certain that a specific issue you found counts as a security issue, we'd love to hear the details, so we can figure out together if the issue in question needds to be addressed. +要报告 go-mail 中的(可能的)安全问题,请发送电子邮件至[security@go-mail.dev](mailto:security@go-mail.dev)或使用 Github 的[私人报告功能](https://github.com/wneessen/go-mail/security/advisories/new)。 我们非常欢迎报告。 即使您不确定您发现的特定问题是否属于安全问题,我们也很乐意听取详细信息,以便我们一起确定是否需要解决该问题。 -Typically, you will receive an answer within a day or even within a few hours. +通常,您会在一天内甚至几个小时内收到答复。 -### End-to-End encryption -You can send OpenPGP/GPG encrpyted mails to the [security@go-mail.dev](mailto:security@go-mail.dev) address. +### 端到端加密 +您可以将 OpenPGP/GPG 加密邮件发送到[security@go-mail.dev](mailto:security@go-mail.dev)地址。 -OpenPGP/GPG public key: +OpenPGP/GPG 公钥: ``` -----BEGIN PGP PUBLIC KEY BLOCK----- xjMEY8RwPBYJKwYBBAHaRw8BAQdAiLsW7pv+CCMq5Ol0hbIB1HnJI97u3zJw From d34021122d30a2eeed0104b9b3ee8116f8c4db10 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 13 Sep 2023 17:05:17 +0200 Subject: [PATCH 18/25] New translations _index.md (German) --- content/de/_index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/de/_index.md b/content/de/_index.md index e75e9fe..f2539c4 100644 --- a/content/de/_index.md +++ b/content/de/_index.md @@ -5,7 +5,7 @@ geekdocNav: false geekdocAnchor: false --- -[![GoDoc](https://godoc.org/github.com/wneessen/go-mail?status.svg)](https://pkg.go.dev/github.com/wneessen/go-mail) [![codecov](https://codecov.io/gh/wneessen/go-mail/branch/main/graph/badge.svg?token=37KWJV03MR)](https://codecov.io/gh/wneessen/go-mail) [![Go Report Card](https://goreportcard.com/badge/github.com/wneessen/go-mail)](https://goreportcard.com/report/github.com/wneessen/go-mail) [![Crowdin](https://badges.crowdin.net/go-mail/localized.svg)](https://crowdin.com/project/go-mail) [![GitHub release](https://img.shields.io/github/v/release/wneessen/go-mail)](https://github.com/wneessen/go-mail/releases/latest) [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go) [![#go-mail on Discord](https://img.shields.io/badge/Discord-%23gomail-blue.svg)](https://discord.gg/dbfQyC4s) [![REUSE status](https://api.reuse.software/badge/github.com/wneessen/go-mail)](https://api.reuse.software/info/github.com/wneessen/go-mail) +[![GoDoc](https://godoc.org/github.com/wneessen/go-mail?status.svg)](https://pkg.go.dev/github.com/wneessen/go-mail) [![codecov](https://codecov.io/gh/wneessen/go-mail/branch/main/graph/badge.svg?token=37KWJV03MR)](https://codecov.io/gh/wneessen/go-mail) [![Go Report Card](https://goreportcard.com/badge/github.com/wneessen/go-mail)](https://goreportcard.com/report/github.com/wneessen/go-mail) [![Crowdin](https://badges.crowdin.net/go-mail/localized.svg)](https://crowdin.com/project/go-mail) [![GitHub release](https://img.shields.io/github/v/release/wneessen/go-mail)](https://github.com/wneessen/go-mail/releases/latest) [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go) [![#go-mail on Discord](https://img.shields.io/badge/Discord-%23gomail-blue.svg)](https://discord.gg/ysQXkaccXk) [![REUSE status](https://api.reuse.software/badge/github.com/wneessen/go-mail)](https://api.reuse.software/info/github.com/wneessen/go-mail) Mastodon Folgen Spendiere mir einen Kaffee @@ -138,5 +138,5 @@ Mit dem Typ `SendError` kann der Benutzer detaillierte Informationen über Zuste {{< /columns >}} ## Unterstützung -Wir haben einen Support- und allgemeinen Diskussionskanal auf Discord. Du findest uns hier: [#go-mail](https://discord.gg/dbfQyC4s) +Wir haben einen Support- und allgemeinen Diskussionskanal auf Discord. Find us at: [#go-mail](https://discord.gg/ysQXkaccXk) From a03cc6d93ee2e706980fc61750f1e94cbdf88857 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 13 Sep 2023 17:05:18 +0200 Subject: [PATCH 19/25] New translations _index.md (Chinese Simplified) --- content/zh/_index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/zh/_index.md b/content/zh/_index.md index 54970bf..a0cdaab 100644 --- a/content/zh/_index.md +++ b/content/zh/_index.md @@ -5,7 +5,7 @@ geekdocNav: false geekdocAnchor: false --- -[![GoDoc](https://godoc.org/github.com/wneessen/go-mail?status.svg)](https://pkg.go.dev/github.com/wneessen/go-mail) [![codecov](https://codecov.io/gh/wneessen/go-mail/branch/main/graph/badge.svg?token=37KWJV03MR)](https://codecov.io/gh/wneessen/go-mail) [![Go Report Card](https://goreportcard.com/badge/github.com/wneessen/go-mail)](https://goreportcard.com/report/github.com/wneessen/go-mail) [![Crowdin](https://badges.crowdin.net/go-mail/localized.svg)](https://crowdin.com/project/go-mail) [![GitHub release](https://img.shields.io/github/v/release/wneessen/go-mail)](https://github.com/wneessen/go-mail/releases/latest) [![在 Awesome Go 中提到](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go) [![#go-mail on Discord](https://img.shields.io/badge/Discord-%23gomail-blue.svg)](https://discord.gg/dbfQyC4s) [![REUSE status](https://api.reuse.software/badge/github.com/wneessen/go-mail)](https://api.reuse.software/info/github.com/wneessen/go-mail) +[![GoDoc](https://godoc.org/github.com/wneessen/go-mail?status.svg)](https://pkg.go.dev/github.com/wneessen/go-mail) [![codecov](https://codecov.io/gh/wneessen/go-mail/branch/main/graph/badge.svg?token=37KWJV03MR)](https://codecov.io/gh/wneessen/go-mail) [![Go Report Card](https://goreportcard.com/badge/github.com/wneessen/go-mail)](https://goreportcard.com/report/github.com/wneessen/go-mail) [![Crowdin](https://badges.crowdin.net/go-mail/localized.svg)](https://crowdin.com/project/go-mail) [![GitHub release](https://img.shields.io/github/v/release/wneessen/go-mail)](https://github.com/wneessen/go-mail/releases/latest) [![在 Awesome Go 中提到](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go) [![#go-mail on Discord](https://img.shields.io/badge/Discord-%23gomail-blue.svg)](https://discord.gg/ysQXkaccXk) [![REUSE status](https://api.reuse.software/badge/github.com/wneessen/go-mail)](https://api.reuse.software/info/github.com/wneessen/go-mail) Mastodon Follow buy ma a coffee @@ -138,5 +138,5 @@ go-mail 提供了请求 MDN(RFC 8098)和 DSN(RFC 1891)的支持 {{< /columns >}} ## 支持 -我们在 Discord 上有一个支持和一般讨论频道。 找到我们:[#go-mail](https://discord.gg/dbfQyC4s) +我们在 Discord 上有一个支持和一般讨论频道。 Find us at: [#go-mail](https://discord.gg/ysQXkaccXk) From 06d136981cb647b6b0822718d625ad3e2b983ccc Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 14 Feb 2024 17:24:21 +0100 Subject: [PATCH 20/25] New translations bulk-mailer.md (German) --- content/de/examples/bulk-mailer.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/de/examples/bulk-mailer.md b/content/de/examples/bulk-mailer.md index 03ad4ec..1ecab66 100644 --- a/content/de/examples/bulk-mailer.md +++ b/content/de/examples/bulk-mailer.md @@ -102,7 +102,7 @@ func main() { // Deliver the mails via SMTP c, err := mail.NewClient("smtp.example.com", - mail.WithSMTPAuth(mail.SMTPAuthPlain), mail.WithTLSPolicy(mail.TLSMandatory), + mail.WithSMTPAuth(mail.SMTPAuthPlain), mail.WithTLSPortPolicy(mail.TLSMandatory), mail.WithUsername(os.Getenv("SMTP_USER")), mail.WithPassword(os.Getenv("SMTP_PASS")), ) if err := c.DialAndSend(ms...); err != nil { From d2097edf212c4ad6a7566aa4b0de58a47e2b1ab5 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 14 Feb 2024 17:24:22 +0100 Subject: [PATCH 21/25] New translations bulk-mailer.md (Chinese Simplified) --- content/zh/examples/bulk-mailer.md | 98 +++++++++++++++++------------- 1 file changed, 57 insertions(+), 41 deletions(-) diff --git a/content/zh/examples/bulk-mailer.md b/content/zh/examples/bulk-mailer.md index 50054c2..9466a16 100644 --- a/content/zh/examples/bulk-mailer.md +++ b/content/zh/examples/bulk-mailer.md @@ -46,53 +46,69 @@ Your marketing team htmlBodyTemplate = `

Hi {{.Firstname}},

we are writing your to let you know that this week we have an amazing offer for you. -// 准备不同的模板 -ttpl, err := tt.New("texttpl").Parse(textBodyTemplate) -if err != nil { - log.Fatalf("failed to parse text template: %s", err) -} -htpl, err := ht.New("htmltpl").Parse(htmlBodyTemplate) -if err != nil { - log.Fatalf("failed to parse text template: %s", err) -} +Using the coupon code "GOMAIL" you will get a 20% discount on all +our products in our online shop.

+

Check out our latest offer on https://acme.com +and use your discount code today!

+

Your marketing team
+  at ACME Inc.

` +) -var ms []*mail.Msg -r := rand.New(rand.NewSource(time.Now().UnixNano())) -for _, u := range ul { - rn := r.Int31() - m := mail.NewMsg() - if err := m.EnvelopeFrom(fmt.Sprintf("noreply+%d@acme.com", rn)); err != nil { - log.Fatalf("failed to set ENVELOPE FROM address: %s", err) +func main() { + // Define a list of users we want to mail to + ul := []User{ + {"Toni", "Tester", "toni.tester@example.com"}, + {"Tina", "Tester", "tina.tester@example.com"}, + {"John", "Doe", "john.doe@example.com"}, } - if err := m.FromFormat(senderName, senderAddr); err != nil { - log.Fatalf("failed to set formatted FROM address: %s", err) - } - if err := m.AddToFormat(fmt.Sprintf("%s %s", u.Firstname, u.Lastname), u.EmailAddr); err != nil { - log.Fatalf("failed to set formatted TO address: %s", err) - } - m.SetMessageID() - m.SetDate() - m.SetBulk() - m.Subject(fmt.Sprintf("%s, we have a great offer for you!", u.Firstname)) - if err := m.SetBodyHTMLTemplate(htpl, u); err != nil { - log.Fatalf("failed to set HTML template as HTML body: %s", err) + + // Prepare the different templates + ttpl, err := tt.New("texttpl").Parse(textBodyTemplate) + if err != nil { + log.Fatalf("failed to parse text template: %s", err) } - if err := m.AddAlternativeTextTemplate(ttpl, u); err != nil { - log.Fatalf("failed to set text template as alternative body: %s", err) + htpl, err := ht.New("htmltpl").Parse(htmlBodyTemplate) + if err != nil { + log.Fatalf("failed to parse text template: %s", err) } - ms = append(ms, m) -} + var ms []*mail.Msg + r := rand.New(rand.NewSource(time.Now().UnixNano())) + for _, u := range ul { + rn := r.Int31() + m := mail.NewMsg() + if err := m.EnvelopeFrom(fmt.Sprintf("noreply+%d@acme.com", rn)); err != nil { + log.Fatalf("failed to set ENVELOPE FROM address: %s", err) + } + if err := m.FromFormat(senderName, senderAddr); err != nil { + log.Fatalf("failed to set formatted FROM address: %s", err) + } + if err := m.AddToFormat(fmt.Sprintf("%s %s", u.Firstname, u.Lastname), u.EmailAddr); err != nil { + log.Fatalf("failed to set formatted TO address: %s", err) + } + m.SetMessageID() + m.SetDate() + m.SetBulk() + m.Subject(fmt.Sprintf("%s, we have a great offer for you!", u.Firstname)) + if err := m.SetBodyHTMLTemplate(htpl, u); err != nil { + log.Fatalf("failed to set HTML template as HTML body: %s", err) + } + if err := m.AddAlternativeTextTemplate(ttpl, u); err != nil { + log.Fatalf("failed to set text template as alternative body: %s", err) + } + + ms = append(ms, m) + } -// 通过SMTP发送邮件 -c, err := mail.NewClient("smtp.example.com", - mail.WithSMTPAuth(mail.SMTPAuthPlain), mail.WithTLSPolicy(mail.TLSMandatory), - mail.WithUsername(os.Getenv("SMTP_USER")), mail.WithPassword(os.Getenv("SMTP_PASS")), -) -if err := c.DialAndSend(ms...); err != nil { - log.Fatalf("failed to deliver mail: %s", err) -} -log.Printf("Bulk mailing successfully delivered.") + // Deliver the mails via SMTP + c, err := mail.NewClient("smtp.example.com", + mail.WithSMTPAuth(mail.SMTPAuthPlain), mail.WithTLSPortPolicy(mail.TLSMandatory), + mail.WithUsername(os.Getenv("SMTP_USER")), mail.WithPassword(os.Getenv("SMTP_PASS")), + ) + if err := c.DialAndSend(ms...); err != nil { + log.Fatalf("failed to deliver mail: %s", err) + } + log.Printf("Bulk mailing successfully delivered.") } ``` From 9a47e5e044ca71a309debd0c72bc5eed8c26176b Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sat, 16 Mar 2024 13:25:37 +0100 Subject: [PATCH 22/25] New translations simple-mailer.md (German) --- content/de/examples/simple-mailer.md | 72 ++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 content/de/examples/simple-mailer.md diff --git a/content/de/examples/simple-mailer.md b/content/de/examples/simple-mailer.md new file mode 100644 index 0000000..a5f173e --- /dev/null +++ b/content/de/examples/simple-mailer.md @@ -0,0 +1,72 @@ +--- +title: Simple Mailer Example +--- + +This example is the most simple piece of code that is required to successfully send a mail with +go-mail. + +```go +package main + +import ( + "log" + "os" + + "github.com/wneessen/go-mail" +) + +func main() { + msg := mail.NewMsg() + if err := msg.From("toni@tester.com"); err != nil { + log.Fatalf("failed to set FROM address: %s", err) + } + if err := msg.To("tina@recipient.org"); err != nil { + log.Fatalf("failed to set TO address: %s", err) + } + msg.Subject("This is my first test mail with go-mail!") + msg.SetBodyString(mail.TypeTextPlain, "This will be the content of the mail.") + + // Deliver the mails via SMTP + c, err := mail.NewClient("smtp.example.com", + mail.WithSMTPAuth(mail.SMTPAuthPlain), mail.WithTLSPortPolicy(mail.TLSMandatory), + mail.WithUsername(os.Getenv("SMTP_USER")), mail.WithPassword(os.Getenv("SMTP_PASS")), + ) + if err != nil { + log.Fatalf("failed to create new mail delivery client: %s", err) + } + if err := c.DialAndSend(msg); err != nil { + log.Fatalf("failed to deliver mail: %s", err) + } + log.Printf("Test mail successfully delivered.") +} +``` + +This example will send a very basic test mail from `toni@tester.com` to `tina@recipient.org`. + +First, in [line 11](#hl-0-11), we create a new `Msg`. The `Msg` type holds everything that is required +for your mail message. Think of it like a new mail within your mail user agent. The `Msg` type +provides you with all of the methods that are required to prepare and format your mail message. + +In [line 12](#hl-0-12) thru [14](#hl-0-14) we set the sender address. In this case it's `toni@tester.com`. +Since go-mail is doing a lot of validation under the hood, it will make sure that the provided mail address +is valid. Therefore we check the returned error. In [line 15](#hl-0-15) thru [17](#hl-0-17) we do the +same for the recipient address. The mail will be sent to `tina@recipient.org`. + +Next, in [line 18](#hl-0-18) we set our subject for our mail message. Followed by setting a simple string +as message body in [line 19](#hl-0-19). The first argument for `Msg.SetBodyString()` is a MIME content type. +In this case we use `mail.TypeTextPlain` for the mail body - so a simple `plain/text` mail body. + +Now that our simple mail message is prepared for delivery, we can create a `Client`. The `Client` in go-mail +handles the connection to a mail server and everything related to it. In [line 22](#hl-0-22) thru +[25](#hl-0-25) we initialize a new `Client` type and give it some options. The first argument is the +mail server we want to connect to. In our example it's `smtp.example.com`. Then we tell the `Client` +that we need to perform SMTP Auth via the `PLAIN` auth method. The `mail.WithSMTPAuth(mail.SMTPAuthPlain)` +option handles this. With the `mail.WithTLSPortPolicy(mail.TLSMandatory)` option, we tell the `Client` +that we require a TLS connection for sending our mail. We set it to mandatory mode, so that the `Client` +will stop processing if it cannot accomplish a TLS secured connection. With the `mail.WithUsername()` +and `mail.WithPassword()` options, we let the `Client` know what username and password to use for the +SMTP auth. [Lines 26-28](#hl-0-26) check if the `Client` invocation worked without errors. + +Finally, in [line 29-32](#hl-0-29) we send out our mail message using our mail client with the +`Client.DialAndSend()` method. We print out a brief message on success or throw an error in case +the delivery failed. From abaddad51b275a671053714856e600c44c07487c Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sat, 16 Mar 2024 13:25:38 +0100 Subject: [PATCH 23/25] New translations simple-mailer.md (Chinese Simplified) --- content/zh/examples/simple-mailer.md | 72 ++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 content/zh/examples/simple-mailer.md diff --git a/content/zh/examples/simple-mailer.md b/content/zh/examples/simple-mailer.md new file mode 100644 index 0000000..a5f173e --- /dev/null +++ b/content/zh/examples/simple-mailer.md @@ -0,0 +1,72 @@ +--- +title: Simple Mailer Example +--- + +This example is the most simple piece of code that is required to successfully send a mail with +go-mail. + +```go +package main + +import ( + "log" + "os" + + "github.com/wneessen/go-mail" +) + +func main() { + msg := mail.NewMsg() + if err := msg.From("toni@tester.com"); err != nil { + log.Fatalf("failed to set FROM address: %s", err) + } + if err := msg.To("tina@recipient.org"); err != nil { + log.Fatalf("failed to set TO address: %s", err) + } + msg.Subject("This is my first test mail with go-mail!") + msg.SetBodyString(mail.TypeTextPlain, "This will be the content of the mail.") + + // Deliver the mails via SMTP + c, err := mail.NewClient("smtp.example.com", + mail.WithSMTPAuth(mail.SMTPAuthPlain), mail.WithTLSPortPolicy(mail.TLSMandatory), + mail.WithUsername(os.Getenv("SMTP_USER")), mail.WithPassword(os.Getenv("SMTP_PASS")), + ) + if err != nil { + log.Fatalf("failed to create new mail delivery client: %s", err) + } + if err := c.DialAndSend(msg); err != nil { + log.Fatalf("failed to deliver mail: %s", err) + } + log.Printf("Test mail successfully delivered.") +} +``` + +This example will send a very basic test mail from `toni@tester.com` to `tina@recipient.org`. + +First, in [line 11](#hl-0-11), we create a new `Msg`. The `Msg` type holds everything that is required +for your mail message. Think of it like a new mail within your mail user agent. The `Msg` type +provides you with all of the methods that are required to prepare and format your mail message. + +In [line 12](#hl-0-12) thru [14](#hl-0-14) we set the sender address. In this case it's `toni@tester.com`. +Since go-mail is doing a lot of validation under the hood, it will make sure that the provided mail address +is valid. Therefore we check the returned error. In [line 15](#hl-0-15) thru [17](#hl-0-17) we do the +same for the recipient address. The mail will be sent to `tina@recipient.org`. + +Next, in [line 18](#hl-0-18) we set our subject for our mail message. Followed by setting a simple string +as message body in [line 19](#hl-0-19). The first argument for `Msg.SetBodyString()` is a MIME content type. +In this case we use `mail.TypeTextPlain` for the mail body - so a simple `plain/text` mail body. + +Now that our simple mail message is prepared for delivery, we can create a `Client`. The `Client` in go-mail +handles the connection to a mail server and everything related to it. In [line 22](#hl-0-22) thru +[25](#hl-0-25) we initialize a new `Client` type and give it some options. The first argument is the +mail server we want to connect to. In our example it's `smtp.example.com`. Then we tell the `Client` +that we need to perform SMTP Auth via the `PLAIN` auth method. The `mail.WithSMTPAuth(mail.SMTPAuthPlain)` +option handles this. With the `mail.WithTLSPortPolicy(mail.TLSMandatory)` option, we tell the `Client` +that we require a TLS connection for sending our mail. We set it to mandatory mode, so that the `Client` +will stop processing if it cannot accomplish a TLS secured connection. With the `mail.WithUsername()` +and `mail.WithPassword()` options, we let the `Client` know what username and password to use for the +SMTP auth. [Lines 26-28](#hl-0-26) check if the `Client` invocation worked without errors. + +Finally, in [line 29-32](#hl-0-29) we send out our mail message using our mail client with the +`Client.DialAndSend()` method. We print out a brief message on success or throw an error in case +the delivery failed. From 3e6f8b384ae2c09a05422336dc84053298fb6224 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sat, 16 Mar 2024 17:07:58 +0100 Subject: [PATCH 24/25] New translations simple-mailer.md (German) --- content/de/examples/simple-mailer.md | 35 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/content/de/examples/simple-mailer.md b/content/de/examples/simple-mailer.md index a5f173e..7ffb299 100644 --- a/content/de/examples/simple-mailer.md +++ b/content/de/examples/simple-mailer.md @@ -1,9 +1,8 @@ --- -title: Simple Mailer Example +title: Einfaches Mailer-Beispiel --- -This example is the most simple piece of code that is required to successfully send a mail with -go-mail. +Dieses Beispiel ist der simpelste Code, der erforderlich ist, um eine E-Mail mit go-mail erfolgreich zu versenden. ```go package main @@ -41,25 +40,25 @@ func main() { } ``` -This example will send a very basic test mail from `toni@tester.com` to `tina@recipient.org`. +In diesem Beispiel wird eine einfache Test-Mail von `toni@tester.com` an `tina@recipient.org` gesendet. -First, in [line 11](#hl-0-11), we create a new `Msg`. The `Msg` type holds everything that is required -for your mail message. Think of it like a new mail within your mail user agent. The `Msg` type -provides you with all of the methods that are required to prepare and format your mail message. +Zunächst erstellen wir in [Zeile 11](#hl-0-11) eine neue `Msg`. Der Typ `Msg` enthält alles, was für +für deine Mailnachricht. Stell dir das wie eine neue Mail in deinem Mail-Benutzer-Agent vor. Der Typ `Msg` +stellt dir alle Methoden zur Verfügung, die du zur Vorbereitung und Formatierung deiner Mailnachricht benötigst. -In [line 12](#hl-0-12) thru [14](#hl-0-14) we set the sender address. In this case it's `toni@tester.com`. -Since go-mail is doing a lot of validation under the hood, it will make sure that the provided mail address -is valid. Therefore we check the returned error. In [line 15](#hl-0-15) thru [17](#hl-0-17) we do the -same for the recipient address. The mail will be sent to `tina@recipient.org`. +In [Zeile 12](#hl-0-12) bis [14](#hl-0-14) legen wir die Absenderadresse fest. In diesem Fall ist es `toni@tester.com`. +Da go-mail unter der Haube eine Menge Validierungen durchführt, stellt es sicher, dass die angegebene Mailadresse +gültig ist. Deshalb prüfen wir den zurückgegebenen Fehler. In [Zeile 15](#hl-0-15) bis [17](#hl-0-17) machen wir das Gleiche +dasselbe für die Empfängeradresse. Die E-Mail wird an `tina@recipient.org` gesendet. -Next, in [line 18](#hl-0-18) we set our subject for our mail message. Followed by setting a simple string -as message body in [line 19](#hl-0-19). The first argument for `Msg.SetBodyString()` is a MIME content type. -In this case we use `mail.TypeTextPlain` for the mail body - so a simple `plain/text` mail body. +Als Nächstes legen wir in [Zeile 18](#hl-0-18) den Betreff für unsere E-Mail-Nachricht fest. Gefolgt vom Setzen einer einfachen Zeichenfolge +als Nachrichtentext in [Zeile 19](#hl-0-19). Das erste Argument für `Msg.SetBodyString()` ist ein MIME Content Type. +In diesem Fall verwenden wir `mail.TypeTextPlain` für den Mailbody - also einen einfachen `plain/text` Mailbody. -Now that our simple mail message is prepared for delivery, we can create a `Client`. The `Client` in go-mail -handles the connection to a mail server and everything related to it. In [line 22](#hl-0-22) thru -[25](#hl-0-25) we initialize a new `Client` type and give it some options. The first argument is the -mail server we want to connect to. In our example it's `smtp.example.com`. Then we tell the `Client` +Jetzt, wo unsere einfache E-Mail-Nachricht für den Versand vorbereitet ist, können wir einen "Client" erstellen. Der `Client` in go-mail +verwaltet die Verbindung zu einem Mailserver und alles, was damit zusammenhängt. In [Zeile 22](#hl-0-22) bis +[25](#hl-0-25) initialisieren wir einen neuen `Client`-Typ und geben ihm einige Optionen. Das erste Argument ist der +Mailserver, mit dem wir uns verbinden wollen. In unserem Beispiel ist es `smtp.example.com`. Then we tell the `Client` that we need to perform SMTP Auth via the `PLAIN` auth method. The `mail.WithSMTPAuth(mail.SMTPAuthPlain)` option handles this. With the `mail.WithTLSPortPolicy(mail.TLSMandatory)` option, we tell the `Client` that we require a TLS connection for sending our mail. We set it to mandatory mode, so that the `Client` From f9143a77de5ef6cebdb01e150a91e8d568adb537 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sat, 16 Mar 2024 17:11:32 +0100 Subject: [PATCH 25/25] New translations simple-mailer.md (German) --- content/de/examples/simple-mailer.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/content/de/examples/simple-mailer.md b/content/de/examples/simple-mailer.md index 7ffb299..0a79ca6 100644 --- a/content/de/examples/simple-mailer.md +++ b/content/de/examples/simple-mailer.md @@ -58,14 +58,14 @@ In diesem Fall verwenden wir `mail.TypeTextPlain` für den Mailbody - also einen Jetzt, wo unsere einfache E-Mail-Nachricht für den Versand vorbereitet ist, können wir einen "Client" erstellen. Der `Client` in go-mail verwaltet die Verbindung zu einem Mailserver und alles, was damit zusammenhängt. In [Zeile 22](#hl-0-22) bis [25](#hl-0-25) initialisieren wir einen neuen `Client`-Typ und geben ihm einige Optionen. Das erste Argument ist der -Mailserver, mit dem wir uns verbinden wollen. In unserem Beispiel ist es `smtp.example.com`. Then we tell the `Client` -that we need to perform SMTP Auth via the `PLAIN` auth method. The `mail.WithSMTPAuth(mail.SMTPAuthPlain)` -option handles this. With the `mail.WithTLSPortPolicy(mail.TLSMandatory)` option, we tell the `Client` -that we require a TLS connection for sending our mail. We set it to mandatory mode, so that the `Client` -will stop processing if it cannot accomplish a TLS secured connection. With the `mail.WithUsername()` -and `mail.WithPassword()` options, we let the `Client` know what username and password to use for the -SMTP auth. [Lines 26-28](#hl-0-26) check if the `Client` invocation worked without errors. +Mailserver, mit dem wir uns verbinden wollen. In unserem Beispiel ist es `smtp.example.com`. Dann teilen wir dem `Client` mit +dass wir die SMTP-Authentifizierung über die Auth-Methode "PLAIN" durchführen müssen. Die Option `mail.WithSMTPAuth(mail.SMTPAuthPlain)` +Option übernimmt dies. Mit der Option `mail.WithTLSPortPolicy(mail.TLSMandatory)` teilen wir dem `Client` +dass wir eine TLS-Verbindung für den Versand unserer Mails benötigen. Wir setzen ihn auf den Zwangsmodus, so dass der `Client` +die Verarbeitung abbricht, wenn er keine TLS-gesicherte Verbindung herstellen kann. Mit den Optionen `mail.WithUsername()` +und `mail.WithPassword()` teilen wir dem `Client` mit, welchen Benutzernamen und welches Passwort er für die +SMTP-Authentifizierung. [Zeilen 26-28](#hl-0-26) prüfe, ob der `Client`-Aufruf ohne Fehler funktioniert hat. -Finally, in [line 29-32](#hl-0-29) we send out our mail message using our mail client with the -`Client.DialAndSend()` method. We print out a brief message on success or throw an error in case -the delivery failed. +Zum Schluss, in [Zeile 29-32](#hl-0-29), senden wir unsere Mail-Nachricht mit unserem Mail-Client mit der +Methode `Client.DialAndSend()`. Bei Erfolg wird eine kurze Nachricht ausgegeben oder ein Fehler gemeldet, wenn +die Zustellung fehlgeschlagen ist.