我正在使用Amazon Simple Email Service java API向接收者发送邮件。 我在标签内的邮件正文中发送URL。 我的用例要求用户双击收到的URL以提示某些操作。 (如确认邮件)
问题是url在接收时被编码。双击它会发现页面未找到(404)错误。
原始网址:http://something.com/confirm/email=abc@hotmail.com®Key=somekey&confirm=true 当我在邮件上双击此URL时,链接将在地址栏中打开,如下所示: http://something.com/confirm/email=abc%40hotmail.com%26regKey=somekey%26confirm=true
我正在使用 AmazonSimpleEmailServiceClient 。代码如下:
SendEmailRequest request = new SendEmailRequest().withSource(sourceAddress);
String confirmationURL="http://something.com/confirm/email=abc@hotmail.com®Key=somekey&confirm=true";
List<String> toAddresses = new ArrayList<String>();
toAddresses.add(toEmail);
Destination dest = new Destination().withToAddresses(toAddresses);
request.setDestination(dest);
Content subjContent = new Content().withData("Confirmation Request");
Message msg = new Message().withSubject(subjContent);
// Include a body in both text and HTML formats
Content textContent = new Content().withData("Dear please go to the following URL:"+
confirmationURL+"\n\n");
Content htmlContent = new Content().withData("<p>Dear please go to the following URL:</p>"+
"<p><a href=\""+confirmationURL+"\">"+confirmationURL+"</a></p>");
Body body = new Body().withHtml(htmlContent).withText(textContent);
msg.setBody(body);
request.setMessage(msg)
更新
刚刚发现,只有当收件人电子邮件位于 hotmail.com 时才会出现此问题。为什么微软总是要做一些不同的事情?有人帮忙!
答案 0 :(得分:0)
使用java.net.URLEncoder类:
String confirmationURL = URLEncoder.encode( "http://something.com/confirm/email=abc@hotmail.com®Key=somekey& confirm=true", "UTF-8");