【问题标题】:how to send url in email without encoding如何在不编码的情况下在电子邮件中发送 url
【发布时间】:2012-08-22 03:38:58
【问题描述】:

我正在使用 Amazon Simple Email Service java API 向收件人发送邮件。 我在标签内的邮件正文中发送 URL。 我的用例要求用户双击收到的 URL 以提示一些操作。 (如确认邮件)

问题是 url 在接收时被编码。双击它会出现找不到页面 (404) 错误。

原始网址http://something.com/confirm/email=abc@hotmail.com&regKey=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&regKey=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 时才会出现此问题。为什么微软总是要做一些不同的事情?有人帮忙!

【问题讨论】:

    标签: java amazon-web-services url-encoding amazon-ses


    【解决方案1】:

    使用类 java.net.URLEncoder:

    String confirmationURL = URLEncoder.encode( "http://something.com/confirm/email=abc@hotmail.com&regKey=somekey& confirm=true", "UTF-8");
    

    【讨论】:

    • 实际编码在hotmail收件人中。我无法解码。
    猜你喜欢
    • 2014-01-01
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-19
    • 2010-10-08
    • 1970-01-01
    相关资源
    最近更新 更多