You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Amazon SES发送含德语变音符号邮箱地址遭拒问题排查

解决Amazon SES发送含德语变音符号邮箱地址被拒绝的问题

问题根源

报错Local address contains control or whitespace的核心原因是:SES要求国际化邮箱地址的**本地部分(@前的内容)**必须遵循RFC 6531规范做MIME编码,而你之前仅用IDN.toAscii()处理域名部分,未对含变音符号的本地部分做正确编码。

正确处理步骤

  1. 拆分邮箱地址:将目标邮箱拆分为本地部分(如hüttem)和域名部分(如byom.de)
  2. 处理域名部分:若域名包含非ASCII字符,用IDN.toAscii()转成Punycode;若域名本身是ASCII格式(本例的byom.de),直接保留即可
  3. 处理本地部分:将本地部分用UTF-8编码后,转换为Quoted-Printable格式(推荐,兼容性更好)或Base64格式,再用引号包裹

Java代码示例

编码国际化邮箱地址

import javax.mail.internet.MimeUtility;
import java.nio.charset.StandardCharsets;
import java.net.IDN;

public String encodeInternationalEmail(String email) throws Exception {
    // 拆分本地与域名部分
    String[] parts = email.split("@");
    String localPart = parts[0];
    String domainPart = parts[1];
    
    // 域名转Punycode(仅当域名含非ASCII字符时生效)
    String encodedDomain = IDN.toAscii(domainPart);
    
    // 本地部分做Quoted-Printable编码
    String encodedLocal = MimeUtility.encodeText(localPart, StandardCharsets.UTF_8.name(), "Q");
    
    // 拼接成符合规范的邮箱地址
    return String.format("\"%s\"@%s", encodedLocal, encodedDomain);
}

在SES发送逻辑中使用编码后的地址

import com.amazonaws.services.simpleemail.model.Destination;
import com.amazonaws.services.simpleemail.model.SendEmailRequest;

// 构造收件人
Destination destination = new Destination()
    .withToAddresses(encodeInternationalEmail("hüttem@byom.de"));

// 构造发送请求
SendEmailRequest request = new SendEmailRequest()
    .withDestination(destination)
    .withSource("your-sender@example.com")
    .withMessage(/* 邮件内容配置 */);

// 调用SES发送
awsSesClient.sendEmail(request);

额外注意事项

  • 确保使用最新版本的AWS Java SDK for SES,旧版本对IDN邮箱的支持存在缺陷
  • 若选择Base64编码本地部分,格式应为=?UTF-8?B?[Base64编码内容]?=@[Punycode域名],但Quoted-Printable格式更易读
  • 可通过javax.mail.internet.InternetAddress.validate()方法校验编码后的地址是否符合规范

内容的提问来源于stack exchange,提问作者Mohamed KHOMSI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 15:14:59