如何向域名中带有变音符号的收件人发送电子邮件?

发布于 2024-11-15 13:09:07 字数 187 浏览 3 评论 0原文

在我的应用程序中,我必须向域名中有变音符号的收件人发送电子邮件。 例子: “test@äöü.test.com”

我正在使用 cfmail 标签,但收到这样的错误: “标签邮件属性的定义无效” “无效的电子邮件地址定义 (test@äöü.test.com)”

有没有办法在 Coldfusion 中向此类收件人发送电子邮件?

In my app I have to send email to recipient who has umlauts in domain name.
Example:
"test@äöü.test.com"

I'm using cfmail tag and I'm getting such error:
"invalid definition for attribute to at tag mail"
"Invalid E-Mail Address definition (test@äöü.test.com)"

Is there any way to send email to such recipients in coldfusion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水染的天色ゝ 2024-11-22 13:09:07

甚至还有一个更简单的解决方案!为什么不使用类中内置的 Oracle:
http://download .oracle.com/javase/6/docs/api/java/net/IDN.html#toUnicode(java.lang.String)

那么你只需要这样做(示例显示从 punycode 到 Unicode):

<cfset strUrl = "xn--land-poa.se" />

<!--- Create a Java URL. --->
<cfset jUrl = CreateObject( "java", "java.net.IDN" ).toUnicode(strUrl) />

<cfoutput>
#jUrl#

您无需下载任何东西!

There is even a easier solution! Why not use Oracles built in class:
http://download.oracle.com/javase/6/docs/api/java/net/IDN.html#toUnicode(java.lang.String)

Then you only have to do this (example shows from punycode to Unicode):

<cfset strUrl = "xn--land-poa.se" />

<!--- Create a Java URL. --->
<cfset jUrl = CreateObject( "java", "java.net.IDN" ).toUnicode(strUrl) />

<cfoutput>
#jUrl#

You don´t have to download anything!

请远离我 2024-11-22 13:09:07

我不是 I18N 专家,但我很感兴趣,进行了调查并提出了以下解决方案。

问题本质上是如何将邮件发送到国际化域名 (IDN),即包含非 ASCII 字符的邮件。 IDN 现在是有效的,但不能被包括 Java 在内的许多系统识别(因此 ColdFusion,它对 CFMAIL 地址字段使用 Java 验证 - 因此您看到的错误)。

为了使系统能够识别 IDN,需要将其转换为名为 Punycode 的 ASCII 形式。例如 müller.org 需要转换为 xn--mller-kva.org

LibIdn 是一个操作系统 java 库,可以执行此操作,以下代码显示了如何使用 Mark Mandel 的 JavaLoader

<cffunction name="convertIdnToAscii" returntype="string" output="false">
    <cfargument name="domain" type="string" required="true">
    <cfscript>
        var local   =   {};
        // these paths assume the JavaLoader folder and the libidn-1.22.jar are in the same folder as the cfm template.
        local.javaLoaderPath    =   "javaLoader.JavaLoader";
        local.idnLibPath    =   ExpandPath( "libidn-1.22.jar" );
        // convert the IDN lib path to an array which is what JavaLoader expects
        local.libPathArray  =   [ local.idnLibPath ];
        //load the IDN Lib
        loader  =   CreateObject( "component",local.javaLoaderPath ).init( local.libPathArray );
        // create an instance of the IDN lib
        local.idn   =   loader.create( "gnu.inet.encoding.IDNA" ).init();
        // convert the domain name
        return local.idn.toASCII( arguments.domain );
    </cfscript>
</cffunction>

<cffunction name="convertIdnAddress" returntype="string" output="false">
    <cfargument name="address" type="string" required="true">
    <cfscript>
        var local   =   {};
        local.domain    =   GetToken( arguments.address,2,"@" );
        local.converted =   convertIdnToAscii( local.domain );
        return  Replace( arguments.address,local.domain,local.converted );
    </cfscript>
</cffunction>

<!--- Loop over a list of addresses and convert them if necessary --->
<cfset processedAddresses   =   []>
<cfloop list="test@äöü.test.com,[email protected]" index="address">
    <cfif( NOT IsValid( "email",address ) )>
        <cfset address  =   convertIdnAddress( address )>
    </cfif>
    <cfmail server="0.0.0.0" from="[email protected]" to="#address#" subject="test">Message</cfmail>
    <cfset ArrayAppend( processedAddresses,address )>
</cfloop>
<cfdump var="#processedAddresses#">

这将发送 2 封电子邮件(到不存在的邮件服务器)并转储转换后的地址:

[电子邮件受保护]

[email protected]

注意:

  1. 要获取 libidn jar 文件,请下载并解压 tar 并在 Java 目录中查找它
  2. 上面假设 libidn jar 和 JavaLoader 包位于在与模板相同的文件夹中包含 CF 代码
  3. 上述内容应该适用于 CF8 及更高版本,尽管我只在CF9上测试过。
  4. 请注意,对于可能因包含 IDN 以外的原因而无效的地址,不会进行错误处理。

I'm no I18N expert but I was intrigued enough to investigate and come up with the following solution.

The problem is essentially how to send mail to Internationalised Domain Names (IDN), i.e. those which contain non-ASCII characters. IDNs are valid nowadays but not recognized by many systems including Java (and therefore ColdFusion, which uses the Java validation for CFMAIL address fields - hence the error you're seeing).

For a system to recognise an IDN it needs to be converted to an ASCII form called Punycode. For example müller.org needs to be converted to xn--mller-kva.org

LibIdn is an OS java library that will do this and the following code shows how you can hook it up to CF using Mark Mandel's JavaLoader.

<cffunction name="convertIdnToAscii" returntype="string" output="false">
    <cfargument name="domain" type="string" required="true">
    <cfscript>
        var local   =   {};
        // these paths assume the JavaLoader folder and the libidn-1.22.jar are in the same folder as the cfm template.
        local.javaLoaderPath    =   "javaLoader.JavaLoader";
        local.idnLibPath    =   ExpandPath( "libidn-1.22.jar" );
        // convert the IDN lib path to an array which is what JavaLoader expects
        local.libPathArray  =   [ local.idnLibPath ];
        //load the IDN Lib
        loader  =   CreateObject( "component",local.javaLoaderPath ).init( local.libPathArray );
        // create an instance of the IDN lib
        local.idn   =   loader.create( "gnu.inet.encoding.IDNA" ).init();
        // convert the domain name
        return local.idn.toASCII( arguments.domain );
    </cfscript>
</cffunction>

<cffunction name="convertIdnAddress" returntype="string" output="false">
    <cfargument name="address" type="string" required="true">
    <cfscript>
        var local   =   {};
        local.domain    =   GetToken( arguments.address,2,"@" );
        local.converted =   convertIdnToAscii( local.domain );
        return  Replace( arguments.address,local.domain,local.converted );
    </cfscript>
</cffunction>

<!--- Loop over a list of addresses and convert them if necessary --->
<cfset processedAddresses   =   []>
<cfloop list="test@äöü.test.com,[email protected]" index="address">
    <cfif( NOT IsValid( "email",address ) )>
        <cfset address  =   convertIdnAddress( address )>
    </cfif>
    <cfmail server="0.0.0.0" from="[email protected]" to="#address#" subject="test">Message</cfmail>
    <cfset ArrayAppend( processedAddresses,address )>
</cfloop>
<cfdump var="#processedAddresses#">

This will send 2 emails (to a non-existent mailserver) and dump the converted addresses:

[email protected]

[email protected]

Notes:

  1. To get the libidn jar file, download and extract the tar and look for it in the Java directory
  2. The above assumes the libidn jar and JavaLoader package are located in the same folder as the template contain the CF code
  3. The above should work on CF8 and above, although I've only tested it on CF9.
  4. Be aware there's no error handling for addresses that might be invalid for reasons other than it containing an IDN.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文