使用 Mailgun 发送带有链接的 HTML 消息

Send HTML message with links using Mailgun

我正在尝试发送基于 HTML 的消息,其中包括 link 在 Java 中使用 mailgun。问题是 HTML 代码在电子邮件客户端中按原样显示,它不会将其呈现为 HTML 格式的内容。

我指的是这个URL中给出的例子-

https://documentation.mailgun.com/user_manual.html#sending-via-api

Client client = Client.create();
       client.addFilter(new HTTPBasicAuthFilter("api",
                       "key-***"));
       WebResource webResource =
               client.resource("https://api.mailgun.net/v3/sandbox***.mailgun.org/" +                            "messages");
       FormDataMultiPart form = new FormDataMultiPart();
       form.field("from", "Admin <admin@test.com>");
       form.field("to", "User <user123@gmail.com>");
       form.field("subject", "Hello User");
       form.field("text", "Testing some Mailgun awesomness! <BR> this should be in new line &lt;BR&gt;this shoud aso be be new line");
       return webResource.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);

任何有使用 mailgun 经验的人都可以帮助我。我需要发送带有可点击 link 的电子邮件(锚标签)。

根据 api 文档尝试以下操作:

 form.field('html','<html><a href="http://whosebug.com">HTML version of the body</a></html>');

我遇到了同样的问题,最终创建了一个 small library 来轻松发送电子邮件,抛出 Mailgun。而且我还尝试使发送基本 HTML 电子邮件变得容易。

你的例子会变成这样:

Configuration configuration = new Configuration()
    .domain("sandbox***.mailgun.org")
    .apiKey("key-***")
    .from("Admin", "admin@test.com");

MailBuilder.using(configuration)
    .to("User", "user123@gmail.com")
    .subject("Hello User")
    .text("I suggest you also include a text-only version of your content")
    .html("Testing some Mailgun awesomness! <BR> this should be in new line" + 
          " &lt;BR&gt;this shoud aso be be new line!")
    .build()
    .send();

对于简单的 HTML 消息,我建议您查看项目中的 MailContent 帮助程序 class。