resend / resend-java

Resend's Java SDK
MIT License
24 stars 1 forks source link

Email not sending #25

Closed richard457 closed 7 months ago

kewynakshlley commented 9 months ago

Hey, @richard457! Thanks for reaching out. Could you please check this example? https://resend.com/docs/api-reference/emails/send-email

Check the Java tab. You will need to send to us the file in a base64 format, this base64 content goes into the 'content' attribute in the Attachment object.

richard457 commented 9 months ago

Thanks, But I tried this



  CreateEmailOptions sendEmailRequest = CreateEmailOptions.builder()
                .from("Acme <onboarding@resend.dev>")
                .to("me@domain.com")
                .subject("Hello World")
                .html("<p>Congrats on sending your <strong>first email</strong>!</p>")
                .build();

        CreateEmailResponse data = resend.emails().send(sendEmailRequest);
        System.out.println(data.getId());  

``
and made sure that I was using the right API key but emails is not sending from my code, anything that I might have missed?
kewynakshlley commented 9 months ago

@richard457 could you please send to an e-mail with a registered domain? In case you have your own domain, you can register it in the Resend platform. If you don't have a private domain, you can use a public domain, such as Gmail.

richard457 commented 9 months ago

I have added custom domain but this domain does not have existing emails on it, what do I need to do? can you point me on article that can help me?

kewynakshlley commented 9 months ago

So, with a registered and verified domain, you can send using contact@muragijimana.com or any other e-mail with the @muragijimana domain. I think that, the problem with your code is that you are sending to a domain that doesn't exists.

Please, try sending to an existing gmail account or any well known domain. For testing purposes, you can use delivered@resend.dev.

richard457 commented 9 months ago

I tried Resend resend = new Resend("re_h6bBee85_DLg");

    CreateEmailOptions sendEmailRequest = CreateEmailOptions.builder()
            .from("Flipper <delivered@resend.dev>")
            .to("info@domain.com")
            .subject("Hello World")
            .html("<p>Congrats on sending your <strong>first email</strong>!</p>")
            .build();

    CreateEmailResponse data = resend.emails().send(sendEmailRequest);
    System.out.println(data.getId()); 

and Resend resend = new Resend("re_h6bBee85_DLgr");

    CreateEmailOptions sendEmailRequest = CreateEmailOptions.builder()
            .from("Flipper <contact@flipper.rw>")
            .to("info@doain.com")
            .subject("Hello World")
            .html("<p>Congrats on sending your <strong>first email</strong>!</p>")
            .build();

    CreateEmailResponse data = resend.emails().send(sendEmailRequest);
    System.out.println(data.getId());  none did work.
kewynakshlley commented 9 months ago

Try changing the 'to' attribute to delivered@resend.dev or to an existing domain. If that doesn't work, send me the error.

richard457 commented 9 months ago

I have no error ``java

SendEmailResponse data = client.emails().send(sendEmailRequest);

System.out.println("Sent resend email with ID: "+data.getId());

`` seems like the above line are not getting executed, I see no error in my log, it just hang

kewynakshlley commented 9 months ago

Not sure why that's happening. In my opinion, it could be 3 things:

1) The domain is not verified (you check it in the Resend platform);

2) The ´to´ field is filled with an email containing a domain that isn't supported (info@domain.com for instance);

3) Invalid API Key.

With this code here, I am able to send e-mails:

public class Main {
    public static void main(String[] args) {
        Resend resend = new Resend("re_123");

        CreateEmailOptions req = CreateEmailOptions.builder()
                .from("Acme <onboarding@resend.dev>")
                .to("kewynakshlley@gmail.com") //it could be delivered@resend.dev>
                .text("Hello, world!")
                .subject("Hello from Java!")
                .build();

        try {
            CreateEmailResponse test = resend.emails().send(req);
            System.out.println(test.getId());
        } catch (ResendException e) {
            throw new RuntimeException(e);
        }
    }
}

I tried Resend resend = new Resend("re_h6bBee85_DLg");

    CreateEmailOptions sendEmailRequest = CreateEmailOptions.builder()
            .from("Flipper <delivered@resend.dev>")
            .to("info@domain.com")
            .subject("Hello World")
            .html("<p>Congrats on sending your <strong>first email</strong>!</p>")
            .build();

    CreateEmailResponse data = resend.emails().send(sendEmailRequest);
    System.out.println(data.getId()); 

and Resend resend = new Resend("re_h6bBee85_DLgr");

    CreateEmailOptions sendEmailRequest = CreateEmailOptions.builder()
            .from("Flipper <contact@flipper.rw>")
            .to("info@doain.com")
            .subject("Hello World")
            .html("<p>Congrats on sending your <strong>first email</strong>!</p>")
            .build();

    CreateEmailResponse data = resend.emails().send(sendEmailRequest);
    System.out.println(data.getId());  none did work.

In this example that you sent, you are using info@domain.com and info@doain.com to in the 'to' and that's a mistake, They are not a known domain.