gen-smtp / gen_smtp Goto Github PK
View Code? Open in Web Editor NEWThe extensible Erlang SMTP client and server library.
License: Other
The extensible Erlang SMTP client and server library.
License: Other
Can this be used to check if an email address exists without sending an email?
Feature-request:
This may be usefull, especialy for massive mail sending, to not force close TCP connection and SMTP session after email was sent via gen_smtp_client
, but (optionaly) move this connection to some kind of connection pool, since SMTP allow to send many mails through one TCP connection (multiple transactions).
So, if you need to send emails to 1000 users of, eg, 'gmail.com', you needn't to open TCP (or maybe SSL and STARTTLS) connection for each mail, but setup pool with max 10 connections per domain and send 100 emails through each of them (transparently, no API changes required).
I'm actualy not sure about:
{Relay, TLS, SSL, Auth}
or all the options from 2'nd argument of send
or smth else)Any thoughts?
Refs:
RFC5321
File: gen_smtp/src/gen_smtp_server_session.erl
.
Getting crash here in base64:decode
:
<<"PLAIN">> when Parameters =/= false ->
% TODO - duplicated below in handle_request waitingauth PLAIN
case binstr:split(base64:decode(Parameters), <<0>>) of
Example: command AUTH PLAIN z
will crash server.
Hi,
we are using erlang to send mail found this gen_smtp very usefully can anyone give me code snippet for sending attachment.
thanks in anticipation
Common test allows us to separate implementation code from testing code and provides a much more cleaner method of writing tests.
Any thoughts on moving it over? I can manage this mundane task if no-one wants to tackle it.
This is smth logically following from #33. But in my case this also leads to failed tests at least in my environment (Ubuntu 13.10, Erlang R16B01) like {badmatch, {error, ssl_not_started}}
.
This is because in R16 ssl
depends also from asn1
application:
$ erl
Erlang R16B02 (erts-5.10.3) [source-b44b726] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]
...
2> application:start(ssl).
{error,{not_started,crypto}}
3> application:start(crypto).
ok
4> application:start(ssl).
{error,{not_started,public_key}}
5> application:start(public_key).
{error,{not_started,asn1}} % public_key now depends on asn1
See: https://github.com/Vagabond/gen_smtp/search?q=application%3Astart&source=c
seems to update "Content-Type" into "text/html"?
You currently can't allow messages of unlimited size like, eg. Postfix does, when you set the max to 0.
It's "MAIL FROM:<…>" and "RCPT TO:<…>", i.e. no spaces between colon and opening brace, see RfC 5321.
See the discussion here:
zotonic/zotonic#284
Iconv is currently used by gen_smtp. To be able to work gen_smtp expects a registered process named iconv. If it can't find it it calls iconv:start/0 and later calls iconv:open(). This means that gen_smtp has quite some knowledge of the internals of iconv.
What I propose to do is to Maas' option #1: remove the code which calls iconv:start
, so it doesn't know about the internals of iconv and just uses a module named iconv to convert. Starting and stopping is arranged elsewere via application:start and a configuration file.
Hi,
Thanks for an awesome tool!
Few months ago, I wanted to send email from my erlang app. I installed different smtp servers like postfix but wasn't able to send email ('coz it was too complicated for me). After a while I came across gen_smtp and it worked.
Yesterday, I reinstalled my Ubuntu. After that I tried to send email but it didn't work. That made me think maybe gen_smtp had dependencies that should be installed before using it. Because, last time I had installed bunch of smtp tools before gen_smtp.
Does gen_smtp have any dependencies? Should my Ubuntu be tuned before using gen_smtp?
Thanks again,
-- buriwoy
Is it possible to export a set of low-level functions in gen_smtp_client
, so I can do something like:
{ok, Socket, _Host, _Banner} = gen_smtp_client:connect(...)
{ok, _} = gen_smtp_client:ehlo(...),
ok = gen_stmp_client:auth(...)
When sending using gen_smtp_client:send/2
I have options like the following.
Options = [{relay,Relay},
{username, UserName},
{password, Passoword},
{retries, 1}]
I am sending a PDF which is about 50k, but there seems to be a loop that uses up all the memory. I am not sure if I am not specifing the retries correctly or whether it is ignored.
At function do_AUTH_each(Socket, Username, Password, ["LOGIN" | Tail]), it handle the reply <<"334 VXNlcm5hbWU6\r\n">>, but reply of some servers may be <<"334 dXNlcm5hbWU6\r\n">>.
Hi,
I would like to use multipart/alternative so I can pass SpamAssassin spam's check.
Unfortunately it seems that when using multipart/alternive, instead of text/html, the DKIM is not valid for the receiver... according to mail-tester.com
sendEncryptedEmail([], _, _, _, _) ->
ok;
sendEncryptedEmail([R|Tail], Subject, HtmlBody, PlainBody, PrivKey) ->
DKIMOptions = [
{s, <<"key1">>},
{d, <<"MyDomain.net">>},
{private_key, {pem_plain, PrivKey}}
],
Row = re:replace(R, "\\s+", "", [global, {return, list}]),
case Row of
[] ->
sendEncryptedEmail(Tail, Subject, HtmlBody, PlainBody, PrivKey);
_ ->
SignedMailBody = case PlainBody of
none ->
mimemail:encode(
{<<"text">>, <<"html">>,
[
{<<"Subject">>, tools:binarize(Subject)},
{<<"From">>, <<"MyDomain <[email protected]>">>},
{<<"To">>, tools:binarize(Row)}
],
[],
HtmlBody
},
[
{dkim, DKIMOptions}
]
);
_ ->
mimemail:encode(
{<<"multipart">>,<<"alternative">>,
[{<<"From">>, <<"MyDomain <[email protected]>">>},
{<<"To">>, tools:binarize(Row)},
{<<"Subject">>, tools:binarize(Subject)}],
[],
[{<<"text">>, <<"plain">>,
[{<<"Content-Type">>, <<"text/plain;charset=utf-8">>},
{<<"Content-Disposition">>, <<"inline">>}],
[],
PlainBody},
{<<"text">>, <<"html">>,
[{<<"Content-Type">>, <<"text/html;charset=utf-8">>},
{<<"Content-Disposition">>, <<"inline">>}],
[],
HtmlBody}]},
[
{dkim, DKIMOptions}
]
)
end,
P = gen_smtp_client:send_blocking({"[email protected]", [Row], SignedMailBody}, [{relay, localhost}]),
sendEncryptedEmail(Tail, Subject, HtmlBody, PlainBody, PrivKey)
end.
The result are :
mailing:sendEncryptedEmail(["[email protected]"], "Hello World", tools:readFile("/var/www/newsletter_11_15_14/emailing.txt"), tools:readFile("/var/www/newsletter_11_15_14/emailing_txt.txt"), tools:readFile("/home/user/private-key.pem")).
The email received is flagged with wrong DKIM.
mailing:sendEncryptedEmail(["[email protected]"], "Hello World", tools:readFile("/var/www/newsletter_11_15_14/emailing.txt"), none, tools:readFile("/home/user/private-key.pem")).
The email received is flagged with good DKIM
Any idea why ? Thanks !
HI,
We can create a server using gen_smtp, and also act as email client. If I want to extend authentication I can use call back modules, how do I send email as if that is sent by gateways? What I am trying to ask here is assume that I am trying to setup the smtp server to receive messages to users using gen_smtp and how do I make gen_smtp to deliver/forward messages to other domains?
I am nerd in SMTP and sorry if silly.
Thanks
I test "smtp.qq.com":
[error] Supervisor boss_mail_sup had child mail_controller started with
boss_mail_controller:start_link([{driver,boss_mail_driver_smtp}]) at <0.397.0> exit with reason
{error,no_more_hosts,{permanent_failure,"smtp.qq.com",auth_failed}} in context child_terminated
Test "smtp.163.com":
[error] Supervisor boss_mail_sup had child mail_controller started with
boss_mail_controller:start_link([{driver,boss_mail_driver_smtp}]) at <0.153.0> exit with reason
{error,no_more_hosts,{permanent_failure,"smtp.163.com",<<"500 Error: bad syntax\r\n">>}} in context child_terminated
Test "smtp.gmail.com" and it works.
And the non-blocking mode should be implemented as a middle-man process or something.
Many tests use iconv:conv_chunked/2. If someone happens to install the most visible erlang_iconv, tests will not pass.
I'm getting this error time to time:
Process <0.14748.2> with 0 neighbours exited with reason: no match of right hand value {error,enotconn} in gen_smtp_server_session:init/1 line 116 in gen_server:init_it/6 line 328
The code is littered with commented out io:format
calls in various places.
Choices:
-ifdef(debug).
-define(TRACE(Format, Args), io:format(Format, Args)).
-else.
-define(TRACE(Format, Args), void).
-endif.
The former is more preferable personally, and could provide operators a much more fine-grained control over their logging.
I'm getting a ton of errors like the ones below, because apparently this server keeps resending the email every few minutes. (I removed the sender email for privacy reasons).
2015-08-11 14:34:23.916 [error] GenServer #PID<0.1065.0> terminating
Last message: {:receive_data, "Received: from HE1PR09MB0170.eurprd09.prod.outlook.com (10.161.117.139) by\r\n HE1PR09MB0171.eurprd09.prod.outlook.com (10.161.117.14) with Microsoft SMTP\r\n Server (TLS) id 15.1.225.19; Tue, 11 Aug 2015 02:44:20 +0000\r\nReceived: from HE1PR09MB0170.eurprd09.prod.outlook.com ([127.0.0.1]) by\r\n HE1PR09MB0170.eurprd09.prod.outlook.com ([10.161.117.139]) with Microsoft\r\n SMTP Server id 15.01.0225.018; Tue, 11 Aug 2015 02:44:20 +0000\r\nFrom: ----------------\r\nTo: \"[email protected]\" <[email protected]>\r\nSubject: =?iso-8859-8-i?B?7vLw5CDg5ejl7ujpOiBXZWxjb21lIHRvIHRoZSBsYXN0IHdlZWsgb2Yg?=\r\n =?iso-8859-8-i?Q?the_course?=\r\nThread-Topic: Welcome to the last week of the course\r\nThread-Index: AQHQ09+brz1NzRBoG0apHQA5sB0/tJ4GF3/1\r\nDate: Tue, 11 Aug 2015 02:44:20 +0000\r\nMessage-ID: <c634fa1e36c54823a57a7d3ba9c122f3@HE1PR09MB0170.eurprd09.prod.outlook.com>\r\nReferences: <0000014f1aa4a6f7-52c6ddaa-12d6-4bb3-bdfe-6954f158974c-000000@email.amazonses.com>\r\nIn-Reply-To: <0000014f1aa4a6f7-52c6ddaa-12d6-4bb3-bdfe-6954f158974c-000000@email.amazonses.com>\r\nX-MS-Has-Attach:\r\nX-Auto-Response-Suppress: All\r\nX-MS-Exchange-Inbox-Rules-Loop: --------------------r\nX-MS-TNEF-Correlator:\r\nauthentication-results: spf=none (sender IP is ) smtp.mailfrom=<>; \r\nx-ms-exchange-parent-message-id: <0000014f1aa4a6f7-52c6ddaa-12d6-4bb3-bdfe-6954f158974c-000000@email.amazonses.com>\r\nauto-submitted: auto-generated\r\nx-ms-exchange-generated-message-source: Mailbox Rules Agent\r\nx-microsoft-exchange-diagnostics: 1;HE1PR09MB0171;5:eJPfuJ6+9alEKg2BAsBv3K7gNFFCeJ0o/zw37SQsGz3NWgEEpJ4ZzmC73c68C006HhpBEVwV/06YiHCQjlj5sT8HHIljWrH8KKduUkDUafrOM4u7th6wDlsIKUjNi0PwwIdT0HIAb84OKUEv7T1gNQ==;24:5BLotqrw0+CGHLy/l0OXOKnotDTQFwi4ioerrZhQxWTJn/O6qD15Ma5O8eIkwiqqEANtmLbUF8B177Vjiaj71UnMwZCM1wcOKI1vd0H2jm0=;20:dGaG2/3N2qe7J35HZX8XVfl2JQo6Fve6vCCd5+nEqunDJ8p8cdEDlSjzu3d9hTy9mXn+x/+N9xatMvOZvxMf7Q==\r\nx-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR09MB0171;\r\nx-microsoft-antispam-prvs: <HE1PR09MB01719B204DFF4629B01C487FB87F0@HE1PR09MB0171.eurprd09.prod.outlook.com>\r\nx-exchange-antispam-report-test: UriScan:(108003899814671);\r\nx-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:HE1PR09MB0171;BCL:0;PCL:0;RULEID:;SRVR:HE1PR09MB0171;\r\nx-forefront-prvs: 066517B35B\r\nx-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(189002)(199003)(17443002)(87936001)(92566002)(40100003)(74482002)(54356999)(64706001)(5002640100001)(450100001)(2656002)(50986999)(106356001)(42382002)(76176999)(224303003)(19300405004)(108616004)(46102003)(5001960100002)(74316001)(77156002)(101416001)(105586002)(588024002)(110136002)(33646002)(5003600100002)(78352002)(2351001)(2950100001)(19580395003)(106116001)(24736003)(5001830100001)(3110400002)(68736005)(558084003)(19625215002)(107886002)(16236675004)(81156007)(62966003)(15975445007)(189998001)(122556002)(102836002)(2501003)(77096005)(76576001)(97736004)(5001860100001)(4001540100001)(229853001)(46342002);DIR:OUT;SFP:1101;SCL:1;SRVR:HE1PR09MB0171;H:HE1PR09MB0170.eurprd09.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:0;A:0;LANG:he;\r\nreceived-spf: None (protection.outlook.com:\r\n HE1PR09MB0170.eurprd09.prod.outlook.com does not designate permitted sender\r\n hosts)\r\nspamdiagnosticoutput: 1:23\r\nspamdiagnosticmetadata: NSPM\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"_000_c634fa1e36c54823a57a7d3ba9c122f3HE1PR09MB0170eurprd09pr_\"\r\nMIME-Version: 1.0\r\nX-OriginatorOrg: ---------\r\nX-MS-Exchange-CrossTenant-originalarrivaltime: 11 Aug 2015 02:44:20.2012\r\n (UTC)\r\nX-MS-Exchange-CrossTenant-fromentityheader: Hosted\r\nX-MS-Exchange-CrossTenant-id: 89549929-c3f4-4716-8ef4-0b2d475c2d50\r\nX-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR09MB0171\r\n\r\n--_000_c634fa1e36c54823a57a7d3ba9c122f3HE1PR09MB0170eurprd09pr_\r\nContent-Type: text/plain; charset=\"iso-8859-8-i\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n=F9=EC=E5=ED,\r\n\r\n=E0=F0=E9 =E1=E7=E5=F4=F9=E4 =F2=E3 16.8.\r\n\r\n=EC=E4=FA=F8=E0=E5=FA, =E4=E2=F8\r\n\r\n--_000_c634fa1e36c54823a57a7d3ba9c122f3HE1PR09MB0170eurprd09pr_\r\nContent-Type: text/html; charset=\"iso-8859-8-i\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n<html xmlns:o=3D\"urn:schemas-microsoft-com:office:office\" xmlns:w=3D\"urn:sc=\r\nhemas-microsoft-com:office:word\" xmlns:m=3D\"http://schemas.microsoft.com/of=\r\nfice/2004/12/omml\" xmlns=3D\"http://www.w3.org/TR/REC-html40\">\r\n<head>\r\n<meta http-equiv=3D\"Content-Type\" content=3D\"text/html; charset=3Diso-8859-=\r\n8-i\">\r\n<meta name=3D\"Generator\" content=3D\"Microsoft Word 15 (filtered medium)\">\r\n<style><!--\r\n/* Font Definitions */\r\n@font-face\r\n\t{font-family:\"Cambria Math\";\r\n\tpanose-1:2 4 5 3 5 4 6 3 2 4;}\r\n@font-face\r\n\t{font-family:Calibri;\r\n\tpanose-1:2 15 5 2 2 2 4 3 2 4;}\r\n@font-face\r\n\t{font-family:Tahoma;\r\n\tpanose-1:2 11 6 4 3 5 4 4 2 4;}\r\n/* Style Definitions */\r\np.MsoNormal, li.MsoNormal, div.MsoNormal\r\n\t{margin:0cm;\r\n\tmargin-bottom:.0001pt;\r\n\ttext-align:right;\r\n\tdirection:rtl;\r\n\tunicode-bidi:embed;\r\n\tfont-size:11.0pt;\r\n\tfont-family:\"Calibri\",\"sans-serif\";}\r\na:link, span.MsoHyperlink\r\n\t{mso-style-priority:99;\r\n\tcolor:#0563C1;\r\n\ttext-decoration:underline;}\r\na:visited, span.MsoHyperlinkFollowed\r\n\t{mso-style-priority:99;\r\n\tcolor:#954F72;\r\n\ttext-decoration:underline;}\r\nspan.EmailStyle17\r\n\t{mso-style-type:personal-compose;\r\n\tfont-family:\"Tahoma\",\"sans-serif\";}\r\n..MsoChpDefault\r\n\t{mso-style-type:export-only;\r\n\tfont-family:\"Calibri\",\"sans-serif\";}\r\n@page WordSection1\r\n\t{size:612.0pt 792.0pt;\r\n\tmargin:72.0pt 90.0pt 72.0pt 90.0pt;}\r\ndiv.WordSection1\r\n\t{page:WordSection1;}\r\n--></style>\r\n</head>\r\n<body lang=3D\"EN-US\" link=3D\"#0563C1\" vlink=3D\"#954F72\">\r\n<div class=3D\"WordSection1\">\r\n<p class=3D\"MsoNormal\" dir=3D\"RTL\" style=3D\"text-autospace:none\"><span lang=\r\n=3D\"HE\" style=3D\"font-size:8.5pt;font-family:"Tahoma","sans-=\r\nserif"\">=F9=EC=E5=ED,</span><span dir=3D\"LTR\" style=3D\"font-size:8.5pt=\r\n;font-family:"Tahoma","sans-serif"\"><o:p></o:p></span><=\r\n/p>\r\n<p class=3D\"MsoNormal\" dir=3D\"RTL\" style=3D\"text-autospace:none\"><span dir=\r\n=3D\"LTR\" style=3D\"font-size:8.5pt;font-family:"Tahoma","sans=\r\n-serif"\"><o:p> </o:p></span></p>\r\n<p class=3D\"MsoNormal\" dir=3D\"RTL\" style=3D\"text-autospace:none\"><span lang=\r\n=3D\"HE\" style=3D\"font-size:8.5pt;font-family:"Tahoma","sans-=\r\nserif"\">=E0=F0=E9 =E1=E7=E5=F4=F9=E4 =F2=E3 16.8.</span><span dir=3D\"L=\r\nTR\" style=3D\"font-size:8.5pt;font-family:"Tahoma","sans-seri=\r\nf"\"><o:p></o:p></span></p>\r\n<p class=3D\"MsoNormal\" dir=3D\"RTL\" style=3D\"text-autospace:none\"><span dir=\r\n=3D\"LTR\" style=3D\"font-size:8.5pt;font-family:"Tahoma","sans=\r\n-serif"\"><o:p> </o:p></span></p>\r\n<p class=3D\"MsoNormal\" dir=3D\"RTL\" style=3D\"text-autospace:none\"><span lang=\r\n=3D\"HE\" style=3D\"font-size:8.5pt;font-family:"Tahoma","sans-=\r\nserif"\">=EC=E4=FA=F8=E0=E5=FA, =E4=E2=F8</span><span dir=3D\"LTR\" style=\r\n=3D\"font-size:8.5pt;font-family:"Tahoma","sans-serif"\">=\r\n<o:p></o:p></span></p>\r\n</div>\r\n</body>\r\n</html>\r\n\r\n--_000_c634fa1e36c54823a57a7d3ba9c122f3HE1PR09MB0170eurprd09pr_--", ""}
State: {:state, {:sslsocket, {:gen_tcp, #Port<0.88739>, :tls_connection, :undefined}, #PID<0.1066.0>}, Mail.SMTPServer, {:envelope, "", ["[email protected]"], "", 0, {"", ""}}, [{'SIZE', '10485670'}, {'8BITMIME', true}, {'PIPELINING', true}], false, :undefined, true, true, %{}, [hostname: 'hekate.oise.utoronto.ca', sessioncount: 1, certfile: 'server.crt', keyfile: 'server.key']}
** (exit) bad return value: {:bad_charset, "iso-8859-8-i"}
According to Wikiepdia, iso-8859-8-i is indeed a valid character encoding. Anyway, even if it were not, I would rather that it just parse it using ASCII or something, instead of blowing up, maybe with a warning - my app sends me an email on every error - and I've gotten a lot of error emails because of this one email that keeps getting resent.
Could any one provide the setup example to connect with gmail smtp server to receive email, Im reading the code and couldn't figure out how i can do that
Hi,
On R18, I'm getting this error in several parts of code:
src/smtp_util.erl:113: Warning: erlang:now/0: Deprecated BIF. See the "Time and Time Correction in Erlang" chapter of the ERTS User's Guide for more information
I've created a fix in this branch:
https://github.com/technion/gen_smtp/tree/timeupdate
The fix doesn't just blindly change to the new timestamp, it includes a wrapper to ensure support for existing versions. Given the intent of erlang:now() in the code has been to produce unique integers, it targets that rather than just identifying the time.
I needed however to place this in a new file in order to silence compiler warnings.
Regardless, the reason I haven't made a PR is because attempting to run tests just gives me several crashes - although they fail on my system regardless of this commit. Example:
in call from gen_smtp_client:'-session_start_test_/0-fun-77-'/1 (src/gen_smtp_client.erl, line 842)
**exit:{{badkey,[{crypto,sign,[sha512,
...
Any feedback appreciated. If you have no issue with tests I'm happy to turn it into a PR.
I have gen_smtp server, started with options
SMTPOpts = [[
{address, SmtpIP},
{port, SmtpPort},
{domain, MxDomain},
{sessionoptions, [{allow_bare_newlines, fix},
{certfile, FullPath(TlsCert)},
{keyfile, FullPath(TlsKey)}]}
]],
and handler with
handle_EHLO(_Hostname, Extensions, State) ->
WithTlsExts = Extensions ++ [{"STARTTLS", true}],
{ok, WithTlsExts, State}.
The strange thing is that I sometimes got errors like this
2013-12-17 23:33:37 =CRASH REPORT====
crasher:
initial call: gen_smtp_server_session:init/1
pid: <0.27270.5>
registered_name: []
exception exit: {{badarg,[{erlang,byte_size,["record overflow"],[]},{binstr,strip,3,[{file,"src/binstr.erl"},{line,258}]},{gen_smtp_server_session,parse_request,1,[{file,"src/gen_smtp_server_session.erl"},{line,241}]},{gen_smtp_server_session,handle_info,2,[{file,"src/gen_smtp_server_session.erl"},{line,189}]},{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,607}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]},[{gen_server,terminate,6,[{file,"gen_server.erl"},{line,747}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]}
I think this happens when https://github.com/Vagabond/gen_smtp/blob/fd0426c46468c33c21332335c267ae6e13e01afb/src/gen_smtp_server_session.erl#L193 receives
{ssl_error, Socket, "record overflow"}
instead of {ssl, Socket, Data}
.
See http://tools.ietf.org/html/rfc2246#section-7.2.2 about "record overflow".
The strange thing is that error happens not immidiately, but after some commands have passed.
Also, this may happen with different clients / relays, sending emails to my gen_smtp. The same client may have successfull and not successful sessions. I mean, sometimes it connect and operate successfuly, but sometimes the same client may fail.
Sample session logs:
2013-12-14 01:58:13.575 [debug] <0.23562.4>@tm_smtp_handler:init:30 Connection from {213,79,65,42}
2013-12-14 01:58:13.739 [debug] <0.23562.4>@tm_smtp_handler:handle_RCPT:57 RCPT to <<"*******@dropmail.me">> not successfully
2013-12-14 01:58:13.741 [debug] <0.23562.4>@tm_smtp_handler:handle_RCPT:57 RCPT to <<"*******@dropmail.me">> not successfully
2013-12-14 01:58:13.742 [debug] <0.23562.4>@tm_smtp_handler:handle_RCPT:57 RCPT to <<"*********@dropmail.me">> not successfully
2013-12-14 01:58:13.743 [debug] <0.23562.4>@tm_smtp_handler:handle_RCPT:57 RCPT to <<"***********@dropmail.me">> not successfully
2013-12-14 01:58:13.744 [debug] <0.23562.4>@tm_smtp_handler:handle_RCPT:57 RCPT to <<"**********@dropmail.me">> not successfully
2013-12-14 01:58:13.745 [debug] <0.23562.4>@tm_smtp_handler:handle_RCPT:57 RCPT to <<"***********@dropmail.me">> not successfully
2013-12-14 01:58:13.746 [debug] <0.23562.4>@tm_smtp_handler:handle_RCPT:57 RCPT to <<"**********@dropmail.me">> not successfully
2013-12-14 01:58:13.747 [debug] <0.23562.4>@tm_smtp_handler:handle_RCPT:57 RCPT to <<"***********@dropmail.me">> not successfully
2013-12-14 01:58:13.849 [error] <0.23562.4> gen_server <0.23562.4> terminated with reason: bad argument in call to erlang:byte_size("record overflow") in binstr:strip/3 line 258
2013-12-14 01:58:13.870 [error] <0.23562.4> CRASH REPORT Process <0.23562.4> with 0 neighbours exited with reason: bad argument in call to erlang:byte_size("record overflow") in binstr:strip/3 line 258 in gen_server:terminate/6 line 747
2013-12-11 10:30:51.070 [debug] <0.21092.3>@tm_smtp_handler:init:30 Connection from {194,67,246,9}
2013-12-11 10:30:51.207 [debug] <0.21092.3>@tm_smtp_handler:handle_RCPT:57 RCPT to <<"*****@dropmail.me">> not successfully
2013-12-11 10:30:51.400 [error] <0.21092.3> gen_server <0.21092.3> terminated with reason: bad argument in call to erlang:byte_size("record overflow") in binstr:strip/3 line 258
2013-12-11 10:30:51.583 [error] <0.21092.3> CRASH REPORT Process <0.21092.3> with 0 neighbours exited with reason: bad argument in call to erlang:byte_size("record overflow") in binstr:strip/3 line 258 in gen_server:terminate/6 line 747
2013-12-11 11:17:33.098 [debug] <0.21514.3>@tm_smtp_handler:init:30 Connection from {194,67,246,9}
2013-12-11 11:17:33.234 [debug] <0.21514.3>@tm_smtp_handler:handle_RCPT:57 RCPT to <<"****@dropmail.me">> not successfully
2013-12-11 11:17:33.314 [error] <0.21514.3> gen_server <0.21514.3> terminated with reason: bad argument in call to erla
ng:byte_size("record overflow") in binstr:strip/3 line 258
2013-12-11 11:17:33.317 [error] <0.21514.3> CRASH REPORT Process <0.21514.3> with 0 neighbours exited with reason: bad argument in call to erlang:byte_size("record overflow") in binstr:strip/3 line 258 in gen_server:terminate/6 line 747
2013-12-11 11:17:45.871 [debug] <0.21516.3>@tm_smtp_handler:init:30 Connection from {194,67,246,9}
2013-12-11 11:17:46.004 [debug] <0.21516.3>@tm_smtp_handler:handle_RCPT:57 RCPT to <<"******@dropmail.me">> not successfully
2013-12-11 11:17:46.117 [error] <0.21516.3> gen_server <0.21516.3> terminated with reason: bad argument in call to erlang:byte_size("record overflow") in binstr:strip/3 line 258
2013-12-11 11:17:46.118 [error] <0.21516.3> CRASH REPORT Process <0.21516.3> with 0 neighbours exited with reason: bad argument in call to erlang:byte_size("record overflow") in binstr:strip/3 line 258 in gen_server:terminate/6 line 747
2013-12-11 11:17:46.713 [debug] <0.21518.3>@tm_smtp_handler:init:30 Connection from {194,67,246,9}
2013-12-11 11:17:46.855 [debug] <0.21518.3>@tm_smtp_handler:handle_RCPT:57 RCPT to <<"*****@10mail.org">> not successfully
2013-12-11 11:17:47.311 [debug] <0.21520.3>@tm_smtp_handler:init:30 Connection from {194,67,246,9}
2013-12-11 11:17:47.444 [debug] <0.21520.3>@tm_smtp_handler:handle_RCPT:57 RCPT to <<"******@10mail.org">> not successful
Erlang R15B01, gen_smtp seriyps@8f6ae4f
I'm not sure if it's exactly gen_smtp issue or just buggy client, but gen_smtp may at least handle {ssl_error, Socket, Reason}
and {tcp_error, Socket, Reason}
more explicitly.
Although most mail clients display utf-8 encoded subject lines / recipients fine, some do not (e.g. Apple Mail). Therefore those values should be escaped using rfc2047.
When I am using the smtp_util:parse_rfc822_addresses, I don't get the same result in function of the values given to the function.
1> smtp_util:parse_rfc822_addresses(["[email protected]"]).
{ok,[{undefined,["[email protected]"]}]}
Ok, this value seems to be right for me with the undefined atom.
2> smtp_util:parse_rfc822_addresses(["[email protected],[email protected]"]).
{ok,[{undefined,"[email protected]"},{undefined,"[email protected]"}]}
For this test, no problem I agree with the result
3> smtp_util:parse_rfc822_addresses(["[email protected]","[email protected]"]).
{ok,[{undefined,["[email protected]","[email protected]"]}]}
and for this test, I don't understand, we have a tuple with a list of emails and not a list of tuples. Why?
Okay, I can split the string with a comma, but I think there is a problem in the result of the parser.
Addresses1 = smtp_util:parse_rfc822_addresses(["[email protected],[email protected]"])
Addresses2 = smtp_util:parse_rfc822_addresses(["[email protected]","[email protected]"])
Addresses = Addresse2
** exception error: no match of right hand side value {ok,
[{undefined,["[email protected]","[email protected]"]}]}
Here are other calls to the function, you can see I have an error with the parsing.
4> smtp_util:parse_rfc822_addresses(["Foo Bar <[email protected]>"]).
{ok,[{"Foo Bar","[email protected]"}]}
5> smtp_util:parse_rfc822_addresses(["Foo Bar <[email protected]>, Bar Foo <[email protected]>"]).
{ok,[{"Foo Bar","[email protected]"},{"Bar Foo","[email protected]"}]}
6> smtp_util:parse_rfc822_addresses(["Foo Bar <[email protected]>", "Bar Foo <[email protected]>"]).
{error,{0,smtp_rfc822_parse,
["syntax error before: ","\"Bar\""]}}
7> smtp_util:parse_rfc822_addresses(["Foo Bar <[email protected]>","[email protected]"]). {error,{0,smtp_rfc822_parse,
["syntax error before: ","\"[email protected]\""]}}
8> smtp_util:parse_rfc822_addresses(["Foo Bar <[email protected]>,[email protected]"]).
{ok,[{"Foo Bar","[email protected]"},{undefined,"[email protected]"}]}
Is it a real issue?
https://gist.github.com/dLuna/6783385
15:03 < dluna> and the other thing is type fixes. -type email() should be "iolist() | function()"
instead of "list() | binary() | function()".
15:04 < dluna> And this goes for like five other places in the code too.
15:04 < dluna> (And those other places should probably use the email() type btw)
diff --git a/src/gen_smtp_client.erl b/src/gen_smtp_client.erl
index 0f1532f..470a3ae 100644
--- a/src/gen_smtp_client.erl
+++ b/src/gen_smtp_client.erl
@@ -167,9 +167,9 @@ try_DATA(Body, Socket, _Extensions) ->
{ok, <<"354", _Rest/binary>>} ->
socket:send(Socket, Body++"\r\n.\r\n"),
case read_possible_multiline_reply(Socket) of
- {ok, <<"250", _Rest/binary>>} ->
+ {ok, <<"250", _Rest2/binary>>} ->
true;
- {ok, <<"4", _Rest/binary>> = Msg} ->
+ {ok, <<"4", _Rest2/binary>> = Msg} ->
throw({temporary_failure, Msg});
{ok, Msg} ->
throw({permanant_failure, Msg})
Mail:
MIME-Version: 1.0
Received: by 10.49.107.74 with HTTP; Sat, 4 May 2013 10:02:04 -0700 (PDT)
Date: Sat, 4 May 2013 21:02:04 +0400
Delivered-To: [email protected]
Message-ID: <CAMZozm52CWSvHnhDu+qd+ct6R1bWvfwHy=H=-VjwgdWP+7Ps+A@mail.gmail.com>
Subject:
From: =?KOI8-R?B?88XSx8XKIPDSz8jP0s/X?= <[email protected]>
To: [email protected]
Content-Type: multipart/mixed; boundary=047d7b672bf44fac7f04dbe76d1f
--047d7b672bf44fac7f04dbe76d1f
Content-Type: multipart/alternative; boundary=047d7b672bf44fac7c04dbe76d1d
--047d7b672bf44fac7c04dbe76d1d
Content-Type: text/plain; charset=ISO-8859-1
--047d7b672bf44fac7c04dbe76d1d
Content-Type: text/html; charset=ISO-8859-1
<div dir="ltr"><br></div>
--047d7b672bf44fac7c04dbe76d1d--
--047d7b672bf44fac7f04dbe76d1f
Content-Type: text/plain; charset=US-ASCII; name="=?KOI8-R?B?1MXT1M/X2cogxsHKzC50eHQ=?="
Content-Disposition: attachment; filename="=?KOI8-R?B?1MXT1M/X2cogxsHKzC4=?=
=?KOI8-R?B?dHh0?="
Content-Transfer-Encoding: base64
X-Attachment-Id: f_hgb1h6xc0
cXdlcXdlCg==
--047d7b672bf44fac7f04dbe76d1f--
Gives:
{<<"multipart">>,<<"mixed">>,
[{<<"MIME-Version">>,<<"1.0">>},
{<<"Received">>,
<<"by 10.49.107.74 with HTTP; Sat, 4 May 2013 10:02:04 -0700 (PDT)">>},
{<<"Date">>,<<"Sat, 4 May 2013 21:02:04 +0400">>},
{<<"Delivered-To">>,<<"[email protected]">>},
{<<"Message-ID">>,
<<"<CAMZozm52CWSvHnhDu+qd+ct6R1bWvfwHy=H=-VjwgdWP+7Ps+A@mail.gmail.com>">>},
{<<"Subject">>,<<>>},
{<<"From">>,
<<208,161,208,181,209,128,208,179,208,181,208,185,32,208,159,209,128,208,
190,209,133,208,190,209,128,13,208,190,32,60,115,101,114,105,121,46,112,
114,64,103,109,97,105,108,46,99,111,109,62>>},
{<<"To">>,<<"[email protected]">>},
{<<"Content-Type">>,
<<"multipart/mixed; boundary=047d7b672bf44fac7f04dbe76d1f">>}],
[{<<"content-type-params">>,
[{<<"boundary">>,<<"047d7b672bf44fac7f04dbe76d1f">>}]},
{<<"disposition">>,<<"inline">>},
{<<"disposition-params">>,[]}],
[{<<"multipart">>,<<"alternative">>,
[{<<"Content-Type">>,
<<"multipart/alternative; boundary=047d7b672bf44fac7c04dbe76d1d">>}],
[{<<"content-type-params">>,
[{<<"boundary">>,<<"047d7b672bf44fac7c04dbe76d1d">>}]},
{<<"disposition">>,<<"inline">>},
{<<"disposition-params">>,[]}],
[{<<"text">>,<<"plain">>,
[{<<"Content-Type">>,<<"text/plain; charset=ISO-8859-1">>}],
[{<<"content-type-params">>,[{<<"charset">>,<<"ISO-8859-1">>}]},
{<<"disposition">>,<<"inline">>},
{<<"disposition-params">>,[]}],
<<"\r\n">>},
{<<"text">>,<<"html">>,
[{<<"Content-Type">>,<<"text/html; charset=ISO-8859-1">>}],
[{<<"content-type-params">>,[{<<"charset">>,<<"ISO-8859-1">>}]},
{<<"disposition">>,<<"inline">>},
{<<"disposition-params">>,[]}],
<<"<div dir=\"ltr\"><br></div>\r\n">>}]},
{<<"text">>,<<"plain">>,
[{<<"Content-Type">>,
<<"text/plain; charset=US-ASCII; name=\"=?KOI8-R?B?1MXT1M/X2cogxsHKzC50eHQ=?=\"">>},
{<<"Content-Disposition">>,
<<"attachment; filename=\"=?KOI8-R?B?1MXT1M/X2cogxsHKzC4=?==?KOI8-R?B?dHh0?=\"">>},
{<<"Content-Transfer-Encoding">>,<<"base64">>},
{<<"X-Attachment-Id">>,<<"f_hgb1h6xc0">>}],
[{<<"content-type-params">>,
[{<<"charset">>,<<"US-ASCII">>},
{<<"name">>,<<"=?KOI8-R?B?1MXT1M/X2cogxsHKzC50eHQ=?=">>}]},
{<<"disposition">>,<<"attachment">>},
{<<"disposition-params">>,
[{<<"filename">>,
<<"=?KOI8-R?B?1MXT1M/X2cogxsHKzC4=?==?KOI8-R?B?dHh0?=">>}]}],
<<"qweqwe\n">>}]}
Note:
{<<"Content-Type">>,
<<"text/plain; charset=US-ASCII; name=\"=?KOI8-R?B?1MXT1M/X2cogxsHKzC50eHQ=?=\"">>}
{<<"Content-Disposition">>,
<<"attachment; filename=\"=?KOI8-R?B?1MXT1M/X2cogxsHKzC4=?==?KOI8-R?B?dHh0?=\"">>},
{<<"name">>,<<"=?KOI8-R?B?1MXT1M/X2cogxsHKzC50eHQ=?=">>}
{<<"filename">>,
<<"=?KOI8-R?B?1MXT1M/X2cogxsHKzC4=?==?KOI8-R?B?dHh0?=">>}
It should be "тестовый файл.txt"
Periods at the start of a line in the DATA section should be escaped using a double periods on outgoing messages and unescaped on incoming messages (see rfc821 section 4.5.2).
This is currently not handled in gen_smtp.
For incoming mail, filtering is easily added to gen_smtp_server_session, but for outgoing mail the responsabilities are not very clear.
Would be helpful to have tagged versions of gen_smtp
lost param
{registered, []},
that causes a problem to generate release upgrade
Erlang R14B03
We need to actually REJECT email if 8bitmime isn't set and the client sends a character > 127.
Also should check the SMTP client's support for it.
The SMTP client should really handle BCC fields properly.
Hex is a package manager for Elixir (and Erlang) -- making a Hex package makes it a lot easier to use in Elixir projects.
It'd be great if you could publish it to Hex too -- I could do it, but you probably want to make your own releases.
This is a followup issue from #77
Right now, because of an oversight, you CANNOT limit message size for sessions initiated via HELO. This is a potentially serious DOS opportunity that should be addressed.
Hi!
My actions:
Email = {
"[email protected]",
["[email protected]"],
<<"From: MW [email protected]\r\nTo: MW [email protected]\r\nSubject: Test\r\n\r\nDit is een test.">>
},
Options = [
{ssl,true},
{no_mx_lookups,true},
{relay,"smtp.gmail.com"},
{username,"[email protected]"},
{password,"my_pass"},
{auth,always},
{port,25}
],
gen_smtp_client:send(Email, Options).
And got this: {error,retries_exceeded, {network_failure,"smtp.gmail.com",{error,timeout}}}
What am I doing wrong?
Reduce complexity and reduce reimplemented code in the Erlang world.
What say ye?
There's some stupid shit like missing boundaries and messed up quoted-printable encoding that we could handle if we wanted to (although every email with these problems I've examined has been spam). There should be an optional flag to enable permissive mode.
... doesn't seem to work if I want to test it with {tls, always}
.
If I try to connect to my company's server with:
gen_smtp_client:send({From, To, etc}, [
{relay, "mycompanyrelay"},
{username, "someusername"},
{password, "the password"},
{auth, always},
{tls, always},
{port, 587}])
it works fine.
I'd like to start a local gen_smtp_server and be able to use the exact same command I am using to send emails through my company's email server.
I started the gen_server with:
gen_smtp_server:start(smtp_server_example, [ [
{protocol, ssl},
{port, 1567},
{address, {127,0,0,1}},
{auth, always},
{username, "netto"},
{password, "nopassword"}]]).
and I when trying to connect to it with the gen_smtp_client()
command above, I am getting a timeout (looks like during ssl negotiation). If I change {tls, always}
to be {ssl, true}
(tls -> ssl), then I get passed the ssl handshake negotiation (but in this case, gen_smtp_client() returns a {error,retries_exceeded, {missing_requirement,{127,0,0,1},auth}}
).
Please advice.
Hello,
I'm using a tool to get the email score to avoid landing in SPAM...
I'm almost perfect with gen_smtp.
However SpamAssassin requires a text version of the email :
Message only has text/html MIME parts. You should also include a text version of your message (text/plain)
How can I do that with gen_smtp ? I haven't found anything in the examples or test to perform this.
Thanks for your help.
My setup:
Router (OpenWRT, with working Erlang environment) -> Laptop (Linux)
On Laptop the gen_smtp_client works correctly.
On Router the gen_smtp_client returns the following error:
([email protected])30> gen_smtp_client:send_blocking({"xxx@yyy", ["xxx@yyy"], "Subject: Test\r\nFrom: Milan\r\nTo: Milan\r\n\r\nTest\r\n"}, [{relay, "smtp.blue4.cz"}]).
{error,retries_exceeded,
{network_failure,"smtp.blue4.cz",{error,closed}}}
The thing is that nullmailer with the same relay works.
Do you have any idea what to look at? Is there anything I can turn on to get debug output?
Thank you!
diff --git a/src/gen_smtp_client.erl b/src/gen_smtp_client.erl
index 0f1532f..470a3ae 100644
--- a/src/gen_smtp_client.erl
+++ b/src/gen_smtp_client.erl
@@ -243,7 +243,7 @@ do_AUTH_each(Socket, Username, Password, ["CRAM-MD5" | Tail]) ->
String = binary_to_list(base64:encode(Username++" "++Digest)),
socket:send(Socket, String++"\r\n"),
case read_possible_multiline_reply(Socket) of
- {ok, "235"++_} ->
+ {ok, <<"235", _Rest/binary>>} ->
%io:format("authentication accepted~n"),
true;
{ok, _Msg} ->
I exactly follow the example in README, although the program runs properly nothing happen to me and I didn't receive any mail in my Gmail box.
Erlang R16B01 (erts-5.10.2) [source] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:false] [dtrace]
Eshell V5.10.2 (abort with ^G)
1> gen_smtp_server:start(smtp_server_example).
=INFO REPORT==== 24-Jul-2013::11:01:18 ===
gen_smtp_server starting at nonode@nohost
{ok,<0.34.0>}
=INFO REPORT==== 24-Jul-2013::11:01:18 ===
gen_smtp_server listening on {0,0,0,0}:2525 via tcp
2> gen_smtp_client:send({"[email protected]", ["[email protected]"], "Subject: testing\r\nFrom: Andrew Thompson \r\nTo: Some Dude \r\n\r\nThis is the email body"},[{relay, "localhost"}, {port, 2525}]).
{ok,<0.38.0>}
peer: {127,0,0,1}
EHLO from creatii.co
Mail from [email protected]
Mail to [email protected]
message from [email protected] to [<<"[email protected]">>] queued as 5fb787e1a9ed86dff33c02d34050ce12, body length 82
3>
Is there a chance for oauth support when connecting to SMTP servers?
https://developers.google.com/gmail/oauth_overview
https://developers.google.com/gmail/xoauth2_protocol
2-legged auth
https://developers.google.com/gmail/oauth_protocol
Erlang oauth 2.0 client
https://github.com/kivra/oauth2_client
I currently need to save the email password in plain text in the Erlang code.
It can be much more secure if I'll be able to use an oauth token.
Thanks
Implement IPv6 support. At the very least make socket.erl ipv6 capable.
Hi I'm trying to send an email from an Elixir server application, like this
:gen_smtp_client.send({to,
['[email protected] <from>'],
'Subject: testing\r\nFrom: ME \r\nTo: Some Dude \r\n\r\nThis is the email body'
},
[{:relay, 'smtp.gmail.com'},
{:username, 'username'},
{:ssl,true},
{:password, 'pw'}
])
but I'm getting this error
{error,no_more_hosts,{permanent_failure,"smtp.gmail.com",<<"555 5.5.2 Syntax error. g25sm113645629yhg.6 - gsmtp\r\n">>}}
FYI, I can do this using a node.js app, so it's not a firewall issue or anything like that.
if anyone can help would appreciate it, if this is not the place for this question pls let me know a better venue
Thanks!
Ritchie
smtp_util:parse_rfc822_addresses("a<b<c>>").
Lead to 100% CPU usage and consume RAM.
But, smth like 'syntax error' expected.
FYI: If I do
f(), {_, Bt} = erlang:process_info(list_to_pid("<0.46.0>"), backtrace), io:format(Bt).
from remote shell, I get
Program counter: 0xb2ebfac0 (smtp_util:scan_rfc822/2 + 4)
CP: 0xb2ebfa84 (smtp_util:parse_rfc822_addresses/1 + 72)
arity = 2
">"
[{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},
......
{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{string,0,[]},{'>',0},{string,0,"b<c"},{'<',0},{string,0,"a"}]
0xb2ab6b60 Return addr 0xb3786024 (erl_eval:do_apply/6 + 208)
0xb2ab6b64 Return addr 0xb37914a8 (shell:exprs/7 + 368)
y(0) []
y(1) none
0xb2ab6b70 Return addr 0xb3790fdc (shell:eval_exprs/7 + 80)
y(0) []
y(1) []
y(2) cmd
y(3) []
y(4) {value,#Fun<shell.5.103280319>}
y(5) {eval,#Fun<shell.21.103280319>}
y(6) 12305
y(7) []
y(8) []
y(9) []
0xb2ab6b9c Return addr 0xb3790db0 (shell:eval_loop/3 + 308)
y(0) []
y(1) []
y(2) []
y(3) []
y(4) <0.33.0>
y(5) Catch 0xb3791050 (shell:eval_exprs/7 + 196)
0xb2ab6bb8 Return addr 0x08259db0 (<terminate process normally>)
y(0) 12305
y(1) <0.33.0>
Since MIME parser can be called indirectly when {callbackoptions, [{parse, true}]}
enabled, this issue looks really dangerous.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.