sloonz / go-mime-message Goto Github PK
View Code? Open in Web Editor NEWMails generation for Go
License: The Unlicense
Mails generation for Go
License: The Unlicense
Hi,
I am trying to send an email with attachments but I only receive one part:
this is the code:
package main
import (
"bytes"
"errors"
"github.com/sloonz/go-mime-message"
"github.com/sloonz/go-qprintable"
"log"
"net/smtp"
)
func main() {
m := message.NewMultipartMessage("alternative", "")
m.SetHeader("Subject", message.EncodeWord("test"))
m1 := message.NewTextMessage(qprintable.UnixTextEncoding, bytes.NewBufferString("this is the text body."))
m1.SetHeader("Content-Type", "text/plain")
m.AddPart(m1)
m2 := message.NewBinaryMessage(bytes.NewBufferString("this is some text as attachment."))
m2.SetHeader("Content-Type", "application/octet-stream")
m.AddPart(m2)
var buf bytes.Buffer
buf.ReadFrom(m)
erri := smtp.SendMail(
"mail.padelclick.com:25",
smtp.PlainAuth("", "test", "test", "mail.example.com"),
"[email protected]",
[]string{"[email protected]"},
buf.Bytes())
}
When trying to pass a MultipartMessage
to AddPart
:
cannot use body (type *message.MultipartMessage) as type *message.Message in function argument
Would be useful for sending text and HTML versions of a message, with attachments:
multipart/related
multipart/alternative
text/plain
text/html
image/png
as described at: http://code.activestate.com/recipes/473810-send-an-html-email-with-embedded-image-and-plain-t/
I need to encode a multipart/mixed
as part of a multipart/alternative
, that means a MultipartMessage
as part of a MultipartMessage
.
The problem is MultipartMessage.AddPart
only supports *Message
.
Is there a way one can convert a *MultipartMessage
into a *Message
?
MultipartMessage
takes responsibility for printing each Message
's headers before their bodies, but there ought to be a way to write a MultipartMessage
with its headers, too. Reading from Body
doesn't do the trick (though it probably shouldn't):
msg := mimeMessage.NewMultipartMessage("related", randomBoundary())
io.Copy(os.Stdout, msg.Body)
only prints:
--xxx
instead of:
Content-Type: multipart/related; boundary="xxx"
--xxx
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.