简体   繁体   中英

Java Mailgun API Call getting Error 400 Bad Request

I am using the code below to send an HTML message. When I make the call, I am getting 400 Bad Request Error. All my parameters look correct. Can anyone see what could be wrong?

public ClientResponse SendHTMLEMailMessage( MailingList aMailingList, String subject, String messageToSend, String pathToFileAttachments ) 
{
    ClientConfig cc = new DefaultClientConfig();
    cc.getClasses().add(MultiPartWriter.class);
    client = Client.create(cc);
    client.addFilter(new HTTPBasicAuthFilter( "api", Config.instance().getApiKey() ) );

    WebResource webResource = client.resource("https://api.mailgun.net/v3/mg.lmsnet.com/messages");
    FormDataMultiPart formData = new FormDataMultiPart();
    formData.field( "from", Config.instance().getLmsEblastFromEmailAddress() );
    formData.field( "bcc", aMailingList.getAddress() );
    formData.field( "subject", "A Message From Lieberman Management Services" );
    formData.field("text", messageToSend );

    return webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, formData);
}

You probably need at least a To address. The mailgun documentation is not very clear about the exact required fields. You should try that. You could just use the same sender address or an invalid destination address in the same domain like no-reply@domain.com .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM