GithubHelp home page GithubHelp logo

resend-go's Introduction

Resend Go SDK

License: MIT Build Release

Installation

To install the Go SDK, simply execute the following command on a terminal:

go get github.com/resend/resend-go/v2

Setup

First, you need to get an API key, which is available in the Resend Dashboard.

Example

import (
    "fmt"
    "github.com/resend/resend-go/v2"
)

func main() {
    apiKey := "re_123"

    client := resend.NewClient(apiKey)

    params := &resend.SendEmailRequest{
        To:      []string{"to@example", "[email protected]"},
        From:    "[email protected]",
        Text:    "hello world",
        Subject: "Hello from Golang",
        Cc:      []string{"[email protected]"},
        Bcc:     []string{"[email protected]"},
        ReplyTo: "[email protected]",
    }

    sent, err := client.Emails.Send(params)
    if err != nil {
        panic(err)
    }
    fmt.Println(sent.Id)
}

You can view all the examples in the examples folder

resend-go's People

Contributors

champ3oy avatar drish avatar jorgejr568 avatar maaslalani avatar oif avatar patrickkabwe avatar samlown avatar stephenlacy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

resend-go's Issues

unable to install v2.1.0

require github.com/resendlabs/resend-go: version "v2.1.0" invalid: should be v0 or v1, not v2

Issue with send mail function

It seems like the API might be responding with incorrect response, something that is not a JSON.

Here's the error message I keep getting

invalid character 's' looking for beginning of value

Here's how I am using the SDK

func SendMail(input Params, data map[string]string) {
	client := resend.NewClient(os.Getenv("resend_api"))
	htmlStr, textStr := readTemplate(input.Template)
	for k, v := range data {
		log.Println(v)
		log.Println("{" + k + "}")
		htmlStr = strings.ReplaceAll(htmlStr, "{"+k+"}", v)
		textStr = strings.ReplaceAll(textStr, "{"+k+"}", v)
	}
	options := &resend.SendEmailRequest{
		From:    "Team Reach <[email protected]>",
		To:      []string{input.To},
		Html:    htmlStr,
		Text:    textStr,
		Subject: input.Subject,
	}
	_, err := client.Emails.Send(options)
	if err != nil {
		panic(err)
		log.Println("error sending email")
	}

}

attachments are not send when performing batch send

It looks like that attachments are send only when emailClient.Emails.SendWithContext is called but not when emailClient.Batch.SendWithContext is called. Not sure where the problem is related to the client or on the service but it would be valuable if this could be investigated and solution to be provided.

Resend client failed to send emails

I am getting this error when running the code below.

error:

error: "Post "https://api.resend.com/emails": tls: failed to verify certificate: x509: certificate signed by unknown authority"

code:

func (e *resendEmailer) SendFromTemplate(ctx context.Context, template template.Template, to string) error {
	resp, err := e.resend.Emails.Send(&resend.SendEmailRequest{
		From:    noReplyEmail,
		To:      []string{to},
		Subject: template.Subject,
		Html:    template.HTML,
	})
	if err != nil {
		log.Ctx(ctx).Error().Err(err).Msg("failed to send email")
		return err
	}

	log.Ctx(ctx).Info().Str("id", resp.Id).Msg("email sent")

	return nil
}

and here is how I initialize the client:

resendClient := resend.NewClient(config.ResendApiKey)

Error while trying to get the module

Hello, I am relatively new to golang.
I was trying to use resend SDK it threw the following error when trying to install.

go: downloading github.com/resend/resend-go v1.7.0
go: github.com/resend/resend-go@v1.7.0: parsing go.mod:
        module declares its path as: github.com/resendlabs/resend-go
                but was required as: github.com/resend/resend-go

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.