3

gen_smtp可以在这里找到

我想要的是让email的内容支持HTML标签,比如<strong>Hello</strong>

将显示为Hello

4

3 回答 3

2

有关消息gen_smtp的示例,请参见mimemail 测试:multipart/alternative

Email = {<<"text">>, <<"html">>, [
  {<<"From">>, <<"me@example.com">>},
  {<<"To">>, <<"you@example.com">>},
  {<<"Subject">>, <<"This is a test">>}],
  #{content_type_params => [
    {<<"charset">>, <<"US-ASCII">>}],
    disposition => <<"inline">>
  },
  <<"This is a <strong>HTML</strong> message with some non-ascii characters øÿ\r\nso there">>},
Encoded = mimemail:encode(Email)
于 2013-06-22T12:12:43.077 回答
2

查看https://github.com/selectel/pat。这是一个易于使用的 SMTP 客户端,您可以使用任何文本,包括 html 标签作为消息的正文。

于 2013-06-22T17:27:01.387 回答
0

mimemail:encode/1@Ward Bekker 给出的答案基本上是正确的,但我花了一段时间proplist才让它像map示例所示的那样工作。我使用了 Erlang Erlang/OTP 23 [erts-11.0.3],但它失败了:

** exception error: no function clause matching proplists:get_value(<<"content-type-params">>, #{disposition => <<"inline">>,<<"content-type-params">> =>              [{<<"charset">>,<<"US-ASCII">>}]},[]) (proplists.erl, line 215)
     in function  mimemail:ensure_content_headers/7 (/Users/sean/Documents/code/erlang/scofblog/_build/default/lib/gen_smtp/src/mimemail.erl, line 661)

以下是修改后的代码和编码后的输出:

Email = {
  <<"text">>,
  <<"html">>,
  [
    {<<"From">>, <<"me@example.com">>},
    {<<"To">>, <<"you@example.com">>},
    {<<"Subject">>, <<"This is a test">>}
  ],
  [{<<"content-type-params">>, [{<<"charset">>, <<"US-ASCII">>}]},
   {<<"disposition">>, <<"inline">>}
  ],
  <<"This is a <strong>HTML</strong> øÿ\r\nso there">>
}.

62> mimemail:encode(Email).
<<"From: me@example.com\r\nTo: you@example.com\r\nSubject: This is a test\r\nContent-Type: text/html;\r\n\tcharset=US-ASCII\r\nCon"...>>

希望这可以节省一些头疼。

于 2020-10-10T20:16:47.647 回答