I'm looking for one of two things:
- An Erlang library that supports sending of emails with attachments
- An example of using gen_smtp to send an email with an attachment, since I have already successfully sent emails with this library
It seems there is very little in the way of SMTP client support with attachments out there, although there are plenty of modules that can send plain text emails via SMTP. Anyone have suggestions?
Also, using Windows - I'm not sure the sendmail route is available?
- Agus, when I try that exact code, as well as similar code, I keep getting the following error, any ideas?:*
** exception error: {badmap,[]}
in function maps:get/3
called as maps:get(content_type_params,[],[])
in call from mimemail:ensure_content_headers/7 (c:/temp/erlang/myapp/_build/default/lib/gen_smtp/src/mimemail.erl, line 667)
in call from mimemail:encode/2 (c:/temp/erlang/myapp/_build/default/lib/gen_smtp/src/mimemail.erl, line 161)
in call from email_test:send_email_with_attachment/0 (c:/temp/erlang/myapp/src/email_test.erl, line 14)
The version of gen_smtp I'm using in rebar.config:{gen_smtp, ".*", {git, "git://github.com/gen-smtp/gen_smtp.git", {branch, master}}}
1条答案
按热度按时间soat7uwm1#
简短回答:您可以使用gen_smtp发送带有附件电子邮件。
如果您使用了
gen_smtp_client:send(Email, Options)
或gen_smtp_client:send_blocking(Email, Options)
,则实际上可以使用mimemail:encode/2
生成Body's Email
变量。下面的代码展示了如何发送带有内嵌正文和2个附件(分别为
test1.txt
和erlang.png
)的邮件。这里的关键是使用multipart/mixed
MIME类型并相应地构造邮件正文。这是您将在邮箱中看到的内容: