Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple mails in CC header #93

Open
anasanzari opened this issue Jul 11, 2017 · 6 comments
Open

Multiple mails in CC header #93

anasanzari opened this issue Jul 11, 2017 · 6 comments

Comments

@anasanzari
Copy link

Can we have a method for adding multiple mails in cc header?

@snailQH
Copy link

snailQH commented Aug 29, 2017

I read the source code and find it supports the multi-mails in cc list. But in a indirect way.
I paste some demo code here:

func dosendmail() {
	var tt []*gomail.Message //m ...*Message
	ccAdd := []string{0: "[email protected]", 1: "[email protected]"}
	for _, ccaddress := range ccAdd {
		m := gomail.NewMessage()
		m.SetHeader("From", fromAdd)
		m.SetHeader("To", toAdd)
		m.SetAddressHeader("Cc", ccaddress, "ccname")
		m.SetHeader("Subject", "Hello!")
		m.SetBody("text/html", "Hello <b>first</b> and <i>second</i>!")
		m.Attach("test.gofile") //attachment
		tt = append(tt, m)      // every mail added here
	}

	d := gomail.NewDialer(smtpAdd, 25, fromAdd, pwd)
	d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
	// Send the email to receiver, first and second.
	if err := d.DialAndSend(tt...); err != nil { //dial and sent via tt
		text := fmt.Sprintf("%v", err)
		if strings.Contains(text, "535 Error: authentication failed") { //sometimes it will fail in authentication,just retry
			fmt.Println(text, "\t", "retrying sending e-mail")
			dosendmail()
		}
	} else {
		fmt.Println("Success")
	}
}

Each one in the cc list will receive one mail which sent to the RECEIVER and cc to himself(can not see others who also in the cc list).
AND, MORE IMPORTANT. THE RECEIVER MAY RECEIVE THE EMAIL MORE THAN ONE TIME DEPENDS ON THE NUMBERS IN THE CC LIST.
You can add more than one email in the To like m.SetHeader("To", "[email protected]", "[email protected]")
Or another way: m.SetHeader("Cc","[email protected]","[email protected]"), it can be parsed into cc list.

@iamdanielyin
Copy link

This works for me m.SetHeader("Cc", "[email protected]", "[email protected]")

@crazy-canux
Copy link

crazy-canux commented Dec 12, 2018

@yinfxs

what is the cc or to list can not hard code?

@zheeeng
Copy link

zheeeng commented Jan 21, 2019

Have the same question

@pedromorgan
Copy link

see #104 and #108

@awsp
Copy link

awsp commented Jun 18, 2019

@crazy-canux

Since SetHeader takes varargs, for non-hard coding way, should it be this way?

list := []string{"[email protected]", "[email protected]"}
m.SetHeader("Cc", list...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants