ainsleyclark / go-mail

📧 A cross platform mail driver for GoLang. Featuring Mailgun, Postal, Postmark, SendGrid, SparkPost & SMTP.
MIT License
179 stars 16 forks source link

Mailgun #2

Closed tsawler closed 3 years ago

tsawler commented 3 years ago

Great package!

The only problem I am running into, and I'm sure it's me, is that when I try to send through mailgun, my HTML message gets rendered in the mail client with the wrong content type (text/plain).

Below is the code used to send, and below is the sample email (raw) received.

That is, the message displayed in the browser appears to have the correct payload, but the user gets to read raw html rather than a nicely formatted message.

Any idea what I'm doing wrong?

cfg := mail.Config{
    URL:         "https://api.mailgun.net/",
    APIKey:      "someapikey",
    FromAddress: mailMessage.FromAddress,
    FromName:    mailMessage.FromName,
    Domain:      "mg.mydomain.com",
}

driver, err := mail.NewClient(mail.MailGun, cfg)
    if err != nil {
    fmt.Println(err)
}

var toSlice []string
toSlice = append(toSlice, mailMessage.ToAddress)

formattedMessage = "<h1>Hello, world</h1>"
plainText := "Hello, world"

tx := &mail.Transmission{
    Recipients: toSlice,
    Subject:    mailMessage.Subject,
    HTML:       formattedMessage,
    PlainText: plainText,
}

rs, err := driver.Send(tx)
    if err != nil {
    fmt.Println(err)
}

fmt.Println(rs)

And here is the resulting message:

Delivered-To: some.person@gmail.com Received: by 2002:a05:6602:2816:0:0:0:0 with SMTP id d22csp709301ioe; Sun, 11 Apr 2021 06:46:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYhhmrpu7UvmoOFLE1Vl0fb2bUd4fYYpfMjrIacwmORyXF9WkHqNdSgejUFlyJNHcr/vT2 X-Received: by 2002:a05:6820:451:: with SMTP id p17mr19136528oou.93.1618148815224; Sun, 11 Apr 2021 06:46:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618148815; cv=none; d=google.com; s=arc-20160816; b=g2Sc5tbiMNl9Lk6GDXfByhcD4pjTiA1zIArM+FhOttmsqvMirqnoE3ZO1K/Q5nHWb4 q5Dx/WNm3a8OiR8d/bg9/XKrK3oFGc5lT6TtEDWi1/RqfYiTdywD5pK2Ug+EoGBQfQBb S1kAqKeka9iYqdQ665link5rBySB602ZuEekGvFDqvzdwPchlOLIkye5Ggr/RIbKcuYf 7JWehr8bSuX1RsTFTCfv6ojJozPDmEdtF6tbAxOca2bA0W6oCqesFC0e0BfdBHu9vhYK IAapYpx7YVLaFwPAgLP6O+POU374Av+19Is9W+dgP0nhA5JvZFCiwnSmhEl9L/l9YSd4 INlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:subject:from:to:message-id:sender:date :content-transfer-encoding:dkim-signature:dkim-signature; bh=CBs4VIi+Hgt2a2XJuW2wr7q/kVgtt7M5U3mvhqs5674=; b=aV7Kc/3pE6pwJZPHAZwqkSVeUCmsDGs777s/ko+Zo53JiMy8nk8IDU92Zef8lDXHS8 9sfejXMiG3Sw4MgiekT8vaul8QgiXgPPnD6m3KhCif+h1AJ7k/y/scvxFeXi8l5bhVMo 8oo1ioE5Xy6UOfK7JQxECnhgQz25VaytycvtEhxB6Rtf6wkRVrrOONB9B4VS8JwU3EzG zQ3y/Qzvisivlb50s1FBDnScBKE6eGQx15rsPxyb/hVWPDcR8VkNsmRVfNkX4n22Y3oZ E8hVsySOo8/ht9/ImMMfPqVC9dwkHg3vZqq15t8X/+WNrWD/gq/DpElPX3urORIFmMZU 7WcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.somedomain.com header.s=pic header.b=VlTzhdjS; dkim=pass header.i=@mailgun.org header.s=mg header.b=uysNa81o; spf=pass (google.com: domain of bounce+a75b79.5d7be0-trevor.sawler=gmail.com@mg.somedomain.com designates 209.61.151.241 as permitted sender) smtp.mailfrom="bounce+a75b79.5d7be0-some-person=gmail.com@mg.somedomain.com" Return-Path: bounce+a75b79.5d7be0-trevor.sawler=gmail.com@mg.somedomain.com Received: from rs241.mailgun.us (rs241.mailgun.us. [209.61.151.241]) by mx.google.com with UTF8SMTPS id c189si9473199oif.183.2021.04.11.06.46.51 for trevor.sawler@gmail.com (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Apr 2021 06:46:55 -0700 (PDT) Received-SPF: pass (google.com: domain of bounce+a75b79.5d7be0-trevor.sawler=gmail.com@mg.somedomain.com designates 209.61.151.241 as permitted sender) client-ip=209.61.151.241; Authentication-Results: mx.google.com; dkim=pass header.i=@mg.somedomain.com header.s=pic header.b=VlTzhdjS; dkim=pass header.i=@mailgun.org header.s=mg header.b=uysNa81o; spf=pass (google.com: domain of bounce+a75b79.5d7be0-trevor.sawler=gmail.com@mg.somedomain.com designates 209.61.151.241 as permitted sender) smtp.mailfrom="bounce+a75b79.5d7be0-trevor.sawler=gmail.com@mg.somedomain.com" DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.somedomain.com; q=dns/txt; s=pic; t=1618148815; h=Mime-Version: Content-Type: Subject: From: To: Message-Id: Sender: Date: Content-Transfer-Encoding: X-Feedback-Id; bh=CBs4VIi+Hgt2a2XJuW2wr7q/kVgtt7M5U3mvhqs5674=; b=VlTzhdjShoQVADb+knojm1mrleJz3KUO4l4Hc20/8rjfG52nYM4JD9Y2Jcc/hCqGbFUunmgd WfhyQtPSwqkw8JWBH2vqRZHyjVWvI58C4C8Wpwuhp84+NTlgO7w9ZtmnoBo8uWyr6kqfzTsS tkxC773nMW0Jb6vv2scwPKgiJm8= DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mailgun.org; q=dns/txt; s=mg; t=1618148815; h=Mime-Version: Content-Type: Subject: From: To: Message-Id: Sender: Date: Content-Transfer-Encoding: X-Feedback-Id; bh=CBs4VIi+Hgt2a2XJuW2wr7q/kVgtt7M5U3mvhqs5674=; b=uysNa81oWS2WPuiiJHGtDTSclAKGgshDcOlfgr3WM5F1LKdaiKE+d8M7bo/MKVehvZR2y1/3 D2w2D604OHt4bXiBe2OIhIxecAeTiIzdfMtLSiDArreCLSCTDlTg5PPZJoK6Ew6quk44283s nEn1iJ6Fs9d/QLnZmVBEM6EJG0c= X-Feedback-Id: 589e0b0bcd1682225498c986:mailgun X-Mailgun-Sending-Ip: 209.61.151.241 X-Mailgun-Sid: WyI2MDliMSIsICJ0cmV2b3Iuc2F3bGVyQGdtYWlsLmNvbSIsICI1ZDdiZTAiXQ== Content-Transfer-Encoding: 7bit Received: by luna.mailgun.net with HTTP; Sun, 11 Apr 2021 13:46:31 +0000 Date: Sun, 11 Apr 2021 13:46:31 +0000 Sender: contact=somedomain.com@mg.somedomain.com Message-Id: 20210411134631.1.2DD403451B7784AE@mg.somedomain.com To: some.peron@gmail.com From: contact@mydomain.com Subject: Password Reset Request Content-Type: text/plain; charset="ascii" Mime-Version: 1.0

Hello, world

ainsleyclark commented 3 years ago

Hi @tsawler,

I'm sure this is a simple fix. Will have a look at it and get back to you as soon as I can!

All the best.

ainsleyclark commented 3 years ago

Hi @tsawler

This should be all fixed with tag v1.0.1

6464771

All the best.

tsawler commented 3 years ago

Thanks!

ainsleyclark commented 3 years ago

No problems @tsawler!