通过Exim发送电子邮件(不含smtp)? [英] Send emails in go through Exim (without smtp)?

查看:194
本文介绍了通过Exim发送电子邮件(不含smtp)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用gopkg.in/gomail.v2发送电子邮件,其中包含以下此处的代码

 包主

导入(
字节
fmt

gopkg.in/gomail.v2


func main(){
m:= gomail.NewMessage()

m.SetHeader(From,me@example.com)
m.SetHeader(To,you@example.com)

m.SetAddressHeader (密件抄送,youbcc@example.com,密件抄送电子邮件)

m.SetHeader(密件抄送,anotherbcc@example.com,yetbcc@example.com)

m.SetHeader(Reply-To,me@example.com)
m.SetHeader(Subject,Subject to gomail to be discuss)
body:=`为什么bcc没有被填充
m.SetBody(text / html,body)

sendMailViaExim(m)

}
func sendMailViaExim(m * gomail.Message)(err error){
cmd:= exec.Command(/ usr / sbin / exim,-t)
cmd.Stdout= os.Stdout
cmd.Stderr = os.Stderr

pw,err:= cmd.StdinPipe()
if err!= nil {
log.Println (err)
return
}

err = cmd.Start()
if err!= nil {
log.Println(err)
return
}

var errs [3] error
_,errs [0] = m.WriteTo(pw)
errs [1] = pw。 Close()
errs [2] = cmd.Wait()
for _,err =范围错误{
if err!= nil {
log.Println(err)
返回
}
}
返回
}

以上代码不会发送到密送抄送电子邮件;

因此,我记录了传递给<$ c $的信息c> exim -t 通过以下代码:


buf:= new(bytes.Buffer)



m.WriteTo(buf)//应该用bcc写入整个msg?



fmt.Println(buf.String( ))


和控制台记录:

  $ go run main.go 
Mime - 版本:1.0
日期:2018年4月23日星期一11:15:54 +0530
收件人:you@example.com
回复:me@example.com
主题:主题是要讨论的gomail
来自:me@example.com
Content-Type:text / html; charset = UTF-8
Content-Transfer-Encoding:quoted-printable

为什么bcc没有被填充

bcc没有进入 exim -t 如何在不使用smtp的情况下实现该功能。

解决方案

我认为这是(以及此处是更改日志条目)。



尽管如此,上述提交所修正的逻辑只适用于实际上
发送消息,实际上,当包实际上与SMTP
服务器交谈时(因为自然, Bcc 不应该被转发经过处理该消息的第一个MTA(可能甚至是第一个MDA-I'm懒读RFC))。



提交正在讨论ssed是指
这部分的相关RFC ,其中实际上提供了三种不同的方式来处理 Bcc 标题
字段。
所以我不知道究竟是否应该为
这个改变指责软件包的作者。



然而,这个看起来像剥离 Bcc 标题,即使是 Message.WriteTo
方法,这也是IMO的错误。
我认为这是一个错误的原因如下:


  • 当包通过SMTP发送邮件时, MTA
    或MDA,并应遵守相关RFC对这些
    类型的邮件代理所定义的规则。

  • 当它只是将消息传递给MDA Exim in your case),
    它是一个纯客户端,而处理 Bcc 头域
    很清楚而不是它的业务 - 它应该委托给第一个
    真实邮件处理代理。



唯一的相关问题/ pull-request我能找到的是
这个,但它看起来像
代码在被包含后被高度重构,所以我不知道
是否引入了我认为是一个错误或没有。



另请参阅



TL; DR



我会在软件包的错误跟踪器中提出问题。



(如果你愿意的话,请把它链接到那里;谢谢。)


I'm currently using "gopkg.in/gomail.v2" to send email with following code found here

package main

import (
    "bytes"
    "fmt"

    "gopkg.in/gomail.v2"
)

func main() {
    m := gomail.NewMessage()

    m.SetHeader("From", "me@example.com")
    m.SetHeader("To", "you@example.com")

    m.SetAddressHeader("Bcc", "youbcc@example.com", "Bcc Email")

    m.SetHeader("Bcc", "anotherbcc@example.com", "yetbcc@example.com")

    m.SetHeader("Reply-To", "me@example.com")
    m.SetHeader("Subject", "Subject is to gomail to be discussed")
    body := `Why is bcc not getting populated`
    m.SetBody("text/html", body)

    sendMailViaExim(m)

}
func sendMailViaExim(m *gomail.Message) (err error) {
    cmd := exec.Command("/usr/sbin/exim", "-t")
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr

    pw, err := cmd.StdinPipe()
    if err != nil {
        log.Println(err)
        return
    }

    err = cmd.Start()
    if err != nil {
        log.Println(err)
        return
    }

    var errs [3]error
    _, errs[0] = m.WriteTo(pw)
    errs[1] = pw.Close()
    errs[2] = cmd.Wait()
    for _, err = range errs {
        if err != nil {
            log.Println(err)
            return
        }
    }
    return
}

The Above code doesn't send to Bcc emails;

So I logged the info that was being passed to exim -t via following code:

buf := new(bytes.Buffer)

m.WriteTo(buf) //should write entire msg with bcc?

fmt.Println(buf.String())

and the console logged :

$ go run main.go
Mime-Version: 1.0
Date: Mon, 23 Apr 2018 11:15:54 +0530
To: you@example.com
Reply-To: me@example.com
Subject: Subject is to gomail to be discussed
From: me@example.com
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Why is bcc not getting populated

bcc is not getting to the exim -t How do I achieve that without using smtp.

解决方案

I think it's this (and here is the changelog entry for it).

Still, the logic fixed by the commit above should only apply to actually sending messages—that is, when the package actually speaks with an SMTP server (because, naturally, Bcc should not be forwarded past the first MTA processing the message (maybe even the first MDA—I'm lazy to read the RFC)).

The commit being discussed refers to this part of a relevant RFC which actually offers three different ways to handle Bcc header fields. So I have no idea whether to actually blame the package author for this change or not.

Yet still, this looks like stripping the Bcc header away even for the Message.WriteTo method, which, IMO, is a mistake. The reason I think this is a mistake is as follows:

  • When the package sends a message via SMTP it works as an MTA or an MDA and should obey the rules defined by the relevant RFCs for these types of mail agents.
  • When it merely streams the message to an MDA (Exim in your case), it works as a pure client, and processing of the Bcc header fields is clearly not its business—it rather should be delegated to the first "real" mail processing agent.

The only relevant issue/pull-request I was able to find is this but it looks like the code was highly refactored after its inclusion so I have no idea whether it introduced what I supposed is a bug or not.

See also this.

TL;DR

I would file an issue in the package's bug tracker.

(If you will do that, please link it there; thanks.)

这篇关于通过Exim发送电子邮件(不含smtp)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆