func (m *mailgunImpl) UpdateCampaign(oldId, name, newId string) error {
	r := simplehttp.NewPostRequest(generateApiUrl(m, campaignsEndpoint) + "/" + oldId)
	r.SetBasicAuth(basicAuthUser, m.ApiKey())
	r.AddFormValue("name", name)
	if newId != "" {
		r.AddFormValue("id", newId)
	}
	_, err := r.MakeRequest()
	return err
}
func (m *mailgunImpl) AddBounce(address, code, error string) error {
	r := simplehttp.NewPostRequest(generateApiUrl(m, bouncesEndpoint))

	r.AddFormValue("address", address)
	if code != "" {
		r.AddFormValue("code", code)
	}
	if error != "" {
		r.AddFormValue("error", error)
	}
	r.SetBasicAuth(basicAuthUser, m.ApiKey())
	_, err := r.MakeRequest()
	return err
}
func (m *mailgunImpl) CreateDomain(name string, smtpPassword string, spamAction bool, wildcard bool) error {
	r := simplehttp.NewPostRequest(generatePublicApiUrl(domainsEndpoint))
	r.SetBasicAuth(basicAuthUser, m.ApiKey())
	r.AddFormValue("name", name)
	r.AddFormValue("smtp_password", smtpPassword)
	if spamAction {
		r.AddFormValue("spam_action", "tag")
	} else {
		r.AddFormValue("spam_action", "disabled")
	}
	r.AddFormValue("wildcard", strconv.FormatBool(wildcard))
	_, err := r.MakeRequest()
	return err
}
func (m *mailgunImpl) Send(message *Message) (mes string, id string, err error) {
	if !message.validateMessage() {
		err = errors.New("Message not valid")
	} else {
		r := simplehttp.NewPostRequest(generateApiUrl(m, messagesEndpoint))
		r.AddFormValue("from", message.from)
		r.AddFormValue("subject", message.subject)
		r.AddFormValue("text", message.text)
		for _, to := range message.to {
			r.AddFormValue("to", to)
		}
		for _, cc := range message.cc {
			r.AddFormValue("cc", cc)
		}
		for _, bcc := range message.bcc {
			r.AddFormValue("bcc", bcc)
		}
		for _, tag := range message.tags {
			r.AddFormValue("o:tag", tag)
		}
		for _, campaign := range message.campaigns {
			r.AddFormValue("o:campaign", campaign)
		}
		if message.html != "" {
			r.AddFormValue("html", message.html)
		}
		if message.dkimSet {
			r.AddFormValue("o:dkim", yesNo(message.dkim))
		}
		if message.deliveryTime != nil {
			r.AddFormValue("o:deliverytime", message.deliveryTime.Format("Mon, 2 Jan 2006 15:04:05 MST"))
		}
		if message.testMode {
			r.AddFormValue("o:testmode", "yes")
		}
		if message.trackingSet {
			r.AddFormValue("o:tracking", yesNo(message.tracking))
		}
		if message.trackingClicksSet {
			r.AddFormValue("o:tracking-clicks", yesNo(message.trackingClicks))
		}
		if message.trackingOpensSet {
			r.AddFormValue("o:tracking-opens", yesNo(message.trackingOpens))
		}
		if message.headers != nil {
			for header, value := range message.headers {
				r.AddFormValue("h:"+header, value)
			}
		}
		if message.variables != nil {
			for variable, value := range message.variables {
				r.AddFormValue("v:"+variable, value)
			}
		}
		r.SetBasicAuth(basicAuthUser, m.ApiKey())

		var response sendMessageResponse
		err = r.MakeJSONRequest(&response)
		if err == nil {
			mes = response.Message
			id = response.Id
		}
	}

	return
}