scorredoira / email Goto Github PK
View Code? Open in Web Editor NEWAn easy way to send emails with attachments in Go
License: MIT License
An easy way to send emails with attachments in Go
License: MIT License
when I attach files, the email received contains no body information. but without attachments,it's ok。
Hi,
We are using below code for send email and there is some memory leak after every mail sent.
mailCompose := email.NewHTMLMessage(strSubject, strMessage)
mailCompose.From = mail.Address{Name: strSenderName, Address: strSenderEmail}
aryTo := strings.Split(strTo, ";")
mailCompose.To = aryTo
if err := email.Send(strSMTPURL, auth, mailCompose); err != nil {
errorHandler(err,"SendEmail : Error in send email.")
return
}
mailCompose = nil
Not able to understand where is the issue. Can you just check is there any issue in my code or library for send email.
Thanks
Sandeep Kumar
I have written a simple wrapper to send an email with multiple attachment:
var m *email.Message
if mail.Html {
m = email.NewHTMLMessage(mail.Subject, mail.Body)
} else {
m = email.NewMessage(mail.Subject, mail.Body)
}
m.From.Address = mail.Sender
m.From.Name = "Rein Games"
m.To = mail.To
m.Cc = mail.Cc
if mail.Attachments != nil && len(mail.Attachments) > 0 {
for _, a := range mail.Attachments {
if a.Inline {
m.Inline(a.FilePath)
} else {
m.Attach(a.FilePath)
}
}
}
auth := smtp.PlainAuth("", mail.Sender, conf.Password, "smtp.gmail.com")
return email.Send("smtp.gmail.com:587", auth, m)
However, using this code only the first attachment is being sent with the email. The subsequent attachments do not get attached. What am I missing?
Thanks,
How can add recepient name in cc header? I can add only email now.
I had an issue when I want to send email with multiple attachment. Pls help me.
Using the LAN email
ESMTP
The input is a variable. I don't want to store on disk to be retrieved again. Can you provide an example of using the variable as output immediately?
var buf []Bytes or something?
Please add a license, MIT would be great!
I've attempted to send an email containing both body text and an attachment, and the text never seems to show. I can do one or the other, but not both.
This might be a long shot, but I was able to use the library to attach an image and send the email, however when I download and open the attachment it says the following
The file “test.png” could not be opened because it is empty.
Here is my code, I have been debugging for awhile maybe a second set of eye can help me find the error
func sendMyEmail() {
m := email.NewMessage("Hi", "this is the body")
m.From = mail.Address{Name: "From", Address: "[email protected]"}
m.To = []string{"[email protected]"}
if err := m.Attach("./img_dump/test.png"); err != nil {
// There is no error here
log.Fatal(err)
}
auth := smtp.PlainAuth("", "[email protected]", "mypassword", "smtp.gmail.com")
if err := email.Send("smtp.gmail.com:587", auth, m); err != nil {
// There is no error here also
log.Fatal(err)
}
}
Thanks
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.