我使用亚马逊简单电子邮件服务java API向收件人发送邮件。我正在标签内的邮件正文中发送URL。我的用例要求用户双击收到的URL来提示一些操作。(如确认邮件)
问题是url在接收时被编码。双击时会出现页面未找到(404)错误。
原始URL: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+"nn");
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时,才会出现此问题。为什么微软总是要采取不同的做法?谁来帮忙!
使用类java.net.URLEncoder:
String confirmationURL = URLEncoder.encode( "http://something.com/confirm/email=abc@hotmail.com®Key=somekey& confirm=true", "UTF-8");