RejectedSoftware Forums

Sign up

Pages: 1 2

Can't send e-mail

import std.stdio;
import vibe.core.log;
import vibe.mail.smtp;

void main()
{

    auto gmail = "bubnenkoff@gmail.com>";
    auto pass = "123123123";
    setLogLevel(LogLevel.verbose4);

    auto settings = new SMTPClientSettings("smtp.gmail.com", 587);
    settings.connectionType = SMTPConnectionType.startTLS;
    settings.authType = SMTPAuthType.login;
    settings.username = gmail;
    settings.password = pass;


    auto mail = new Mail;
    mail.headers["From"] = gmail;
    mail.headers["Subject"] = "Testmail";
    mail.bodyText = "Hello, World!";	

    mail.headers["From"] = "<bubnenkoff@gmail.com>";
    mail.headers["To"] = "<bubnenkoff@gmail.com>";

    logInfo("Sending mail...");
    sendMail(settings, mail);
    logInfo("done.");

}
Running .\test.exe
Sending mail...
dnsresolve smtp.gmail.com
dnsresolve yield
dnsresolve ret
Socket event on fd 340: 128 (BA7294 vs BA7294)
Connect result status: 128
leastSize waiting for new data.
socket 340 read event!
evbuffer_read 52 bytes (fd 340)
 .. got 52 bytes
read data
evbuffer_add (fd 340): 16 B
leastSize waiting for new data.
socket 340 write event (false)!
leastSize waiting for new data.
socket 340 read event!
evbuffer_read 49 bytes (fd 340)
 .. got 49 bytes
read data
EHLO response: 250-mx.google.com at your service, [5.35.46.29]
evbuffer_read 19 bytes (fd 340)
 .. got 19 bytes
read data
EHLO response: 250-SIZE 35882577
evbuffer_read 14 bytes (fd 340)
 .. got 14 bytes
read data
EHLO response: 250-8BITMIME
evbuffer_read 14 bytes (fd 340)
 .. got 14 bytes
read data
EHLO response: 250-STARTTLS
evbuffer_read 25 bytes (fd 340)
 .. got 25 bytes
read data
EHLO response: 250-ENHANCEDSTATUSCODES
evbuffer_read 16 bytes (fd 340)
 .. got 16 bytes
read data
EHLO response: 250-PIPELINING
evbuffer_read 14 bytes (fd 340)
 .. got 14 bytes
read data
EHLO response: 250-CHUNKING
evbuffer_read 14 bytes (fd 340)
 .. got 14 bytes
read data
EHLO response: 250 SMTPUTF8
evbuffer_add (fd 340): 10 B
leastSize waiting for new data.
socket 340 write event (false)!
leastSize waiting for new data.
socket 340 read event!
evbuffer_read 30 bytes (fd 340)
 .. got 30 bytes
read data
evbuffer_add (fd 340): 244 B
leastSize waiting for new data.
socket 340 write event (false)!
leastSize waiting for new data.
socket 340 read event!
evbuffer_read 7 bytes (fd 340)
 .. got 7 bytes
read data
Closing socket 340...
...socket 340 closed.
object.Exception@C:\Users\Dima\AppData\Roaming\dub\packages\vibe-d-0.7.23\source
\vibe\stream\openssl.d(281): Failed to connect SSL tunnel.: error:1407741A:SSL r
outines:SSL23_GET_SERVER_HELLO:tlsv1 alert decode error (336032794)

Re: Can't send e-mail

On 2015-05-17 14:40, Suliman wrote:> object.Exception@C:\Users\Dima\AppData\Roaming\dub\packages\vibe-d-0.7.23\source

\vibe\stream\openssl.d(281): Failed to connect SSL tunnel.: error:1407741A:SSL r
outines:SSL23GETSERVER_HELLO:tlsv1 alert decode error (336032794)

Sounds very likely to be due to the removal of SSLv3, google returns a TLSv1 error because that's the oldest supported version.

Easiest solution would be to replace this:
https://github.com/rejectedsoftware/vibe.d/blob/058c45d3eb6afc428f961bdea786c2d4954854dc/source/vibe/stream/openssl.d#L329

with tlsv1

Re: Can't send e-mail

Am 18.05.2015 um 02:44 schrieb Etienne Cimon:

On 2015-05-17 14:40, Suliman wrote:> object.Exception@C:\Users\Dima\AppData\Roaming\dub\packages\vibe-d-0.7.23\source

\vibe\stream\openssl.d(281): Failed to connect SSL tunnel.: error:1407741A:SSL r
outines:SSL23GETSERVER_HELLO:tlsv1 alert decode error (336032794)

Sounds very likely to be due to the removal of SSLv3, google returns a TLSv1 error because that's the oldest supported version.

Easiest solution would be to replace this:
https://github.com/rejectedsoftware/vibe.d/blob/058c45d3eb6afc428f961bdea786c2d4954854dc/source/vibe/stream/openssl.d#L329

with tlsv1

Despite the name, SSLv23_*_method matches all TLS versions, too. On
the other hand, the TLSv1 one matches only TLS 1.0 and not 1.1 or
1.2. At least this was true for the server methods and the SSL versions
with which I have tested.

If anyone has any more insights, any improvement is welcome here!

Re: Can't send e-mail

Do you mean do something like this:

final switch (ver) {
case SSLVersion.tls1: method = SSLv23_client_method(); break; // fix here
case SSLVersion.ssl3: method = SSLv3_client_method(); break;
//case SSLVersion.tls1: method = TLSv1_client_method(); break;
case SSLVersion.dtls1: method = DTLSv1_client_method(); break;
				}

and then recompile project? Maybe there any way to specify what I need in my app?

Re: Can't send e-mail

On Mon, 18 May 2015 13:09:18 GMT, Suliman wrote:

Do you mean do something like this:

final switch (ver) {
case SSLVersion.tls1: method = SSLv23_client_method(); break; // fix here
case SSLVersion.ssl3: method = SSLv3_client_method(); break;
//case SSLVersion.tls1: method = TLSv1_client_method(); break;
case SSLVersion.dtls1: method = DTLSv1_client_method(); break;
				}

and then recompile project? Maybe there any way to specify what I need in my app?

I just tried and actually TLS seems to be the issue (SSL 3 works fine). Changing the line around smtp.d:165 to:

auto ctx = createTLSContext(TLSContextKind.client, TLSVersion.ssl3)

Fixes the issue. Judging by some Google results, this seems to be a general interoperability issue with newer OpenSSL versions. See also: http://serverfault.com/questions/588125/openssl-update-1-0-1f-to-1-0-1g-broke-sendmail-ssl23-get-server-hellotlsv1-ale

It's kind of strange that such an error still exists (introduced in 1.0.1g and still in 1.0.1m) when it occurs with such a major e-mail provider. It seems like the only sensible fix I can provide is to add a tlsVersion field to SMTPClientSettings.

Re: Can't send e-mail

Am 19.05.2015 um 10:33 schrieb Sönke Ludwig:

On Mon, 18 May 2015 13:09:18 GMT, Suliman wrote:

Do you mean do something like this:

final switch (ver) {
case SSLVersion.tls1: method = SSLv23_client_method(); break; // fix here
case SSLVersion.ssl3: method = SSLv3_client_method(); break;
//case SSLVersion.tls1: method = TLSv1_client_method(); break;
case SSLVersion.dtls1: method = DTLSv1_client_method(); break;
				}

and then recompile project? Maybe there any way to specify what I need in my app?

I just tried and actually TLS seems to be the issue (SSL 3 works fine). Changing the line around smtp.d:165 to:

auto ctx = createTLSContext(TLSContextKind.client, TLSVersion.ssl3)

Fixes the issue. Judging by some Google results, this seems to be a general interoperability issue with newer OpenSSL versions. See also: http://serverfault.com/questions/588125/openssl-update-1-0-1f-to-1-0-1g-broke-sendmail-ssl23-get-server-hellotlsv1-ale

It's kind of strange that such an error still exists (introduced in 1.0.1g and still in 1.0.1m) when it occurs with such a major e-mail provider. It seems like the only sensible fix I can provide is to add a tlsVersion field to SMTPClientSettings.

Okay, on Git master, adding the following lines to the example should
make it work:

 settings.tlsVersion = TLSVersion.ssl3;
 settings.tlsValidationMode = TLSPeerValidationMode.validCert;

Re: Can't send e-mail

I still can't get it work.

My app dub.json have section:

"dependencies": {

"vibe-d": "~>0.7.19",
}

also I downloaded last vibed version from git and put it to: \AppData\Roaming\dub\packages\vibe-d-0.7.23\source\vibe

than I added:

    settings.authType = SMTPAuthType.login;
	settings.tlsVersion = TLSVersion.ssl3;

to my App.

So it's become:

import std.stdio;
import vibe.core.log;
import vibe.mail.smtp;

void main()
{

    auto gmail = "bubnenkoff@gmail.com>";
    auto pass = "12312312";
    setLogLevel(LogLevel.verbose4);

    auto settings = new SMTPClientSettings("smtp.gmail.com", 587);
    settings.connectionType = SMTPConnectionType.startTLS;
    settings.authType = SMTPAuthType.login;
	settings.tlsVersion = TLSVersion.ssl3;
	settings.tlsValidationMode = TLSPeerValidationMode.validCert;

    settings.username = gmail;
    settings.password = pass;


    auto mail = new Mail;
    mail.headers["From"] = gmail;
    mail.headers["Subject"] = "Testmail";
    mail.bodyText = "Hello, World!";	

    mail.headers["From"] = "<bubnenkoff@gmail.com>";
    mail.headers["To"] = "<bubnenkoff@gmail.com>";

    logInfo("Sending mail...");
    sendMail(settings, mail);
    logInfo("done.");

}

and now I am getting error:

source\app.d(15): Error: undefined identifier TLSVersion
source\app.d(16): Error: undefined identifier TLSPeerValidationMode

Re: Can't send e-mail

Am 19.05.2015 um 12:14 schrieb Suliman:

(...)

and now I am getting error:

source\app.d(15): Error: undefined identifier TLSVersion
source\app.d(16): Error: undefined identifier TLSPeerValidationMode

Sorry, forgot the import vibe.stream.tls; that you also need to add!

Re: Can't send e-mail

D:\code\test>dub run
Target vibe-d 0.7.23 is up to date. Use --force to rebuild.
Target test ~master is up to date. Use --force to rebuild.
Copying files for vibe-d...
Running .\test.exe
Sending mail...
dnsresolve smtp.gmail.com
dnsresolve yield
dnsresolve ret
Socket event on fd 376: 128 (B4BD74 vs B4BD74)
Connect result status: 128
leastSize waiting for new data.
socket 376 read event!
evbuffer_read 52 bytes (fd 376)
 .. got 52 bytes
read data
evbuffer_add (fd 376): 16 B
leastSize waiting for new data.
socket 376 write event (false)!
leastSize waiting for new data.
socket 376 read event!
evbuffer_read 52 bytes (fd 376)
 .. got 52 bytes
read data
EHLO response: 250-mx.google.com at your service, [83.69.213.227]
evbuffer_read 19 bytes (fd 376)
 .. got 19 bytes
read data
EHLO response: 250-SIZE 35882577
evbuffer_read 14 bytes (fd 376)
 .. got 14 bytes
read data
EHLO response: 250-8BITMIME
evbuffer_read 14 bytes (fd 376)
 .. got 14 bytes
read data
EHLO response: 250-STARTTLS
evbuffer_read 25 bytes (fd 376)
 .. got 25 bytes
read data
EHLO response: 250-ENHANCEDSTATUSCODES
evbuffer_read 16 bytes (fd 376)
 .. got 16 bytes
read data
EHLO response: 250-PIPELINING
evbuffer_read 14 bytes (fd 376)
 .. got 14 bytes
read data
EHLO response: 250-CHUNKING
evbuffer_read 14 bytes (fd 376)
 .. got 14 bytes
read data
EHLO response: 250 SMTPUTF8
evbuffer_add (fd 376): 10 B
leastSize waiting for new data.
socket 376 write event (false)!
leastSize waiting for new data.
socket 376 read event!
evbuffer_read 30 bytes (fd 376)
 .. got 30 bytes
read data
evbuffer_add (fd 376): 76 B
leastSize waiting for new data.
socket 376 write event (false)!
leastSize waiting for new data.
socket 376 read event!
evbuffer_read 5 bytes (fd 376)
 .. got 5 bytes
read data
evbuffer_read 81 bytes (fd 376)
 .. got 81 bytes
read data
evbuffer_read 5 bytes (fd 376)
 .. got 5 bytes
read data
evbuffer_read 1339 bytes (fd 376)
 .. got 1339 bytes
read data
leastSize waiting for new data.
socket 376 read event!
evbuffer_read 1732 bytes (fd 376)
 .. got 1732 bytes
read data
validate callback for /C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
SSL cert initial error: unable to get local issuer certificate
SSL cert not trusted or unknown issuer: /C=US/O=Equifax/OU=Equifax Secure Certif
icate Authority
SSL validation result: 1 (0)
validate callback for /C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
SSL cert initial error: certificate not trusted
SSL cert not trusted or unknown issuer: /C=US/O=Equifax/OU=Equifax Secure Certif
icate Authority
SSL validation result: 1 (0)
validate callback for /C=US/O=Google Inc/CN=Google Internet Authority G2
SSL validation result: 1 (0)
validate callback for /C=US/ST=California/L=Mountain View/O=Google Inc/CN=smtp.g
mail.com
SSL validation result: 1 (0)
evbuffer_read 5 bytes (fd 376)
 .. got 5 bytes
read data
evbuffer_read 331 bytes (fd 376)
 .. got 331 bytes
read data
evbuffer_read 5 bytes (fd 376)
 .. got 5 bytes
read data
evbuffer_read 4 bytes (fd 376)
 .. got 4 bytes
read data
evbuffer_add (fd 376): 150 B
leastSize waiting for new data.
socket 376 write event (false)!
leastSize waiting for new data.
socket 376 read event!
evbuffer_read 5 bytes (fd 376)
 .. got 5 bytes
read data
evbuffer_read 1 bytes (fd 376)
 .. got 1 bytes
read data
evbuffer_read 5 bytes (fd 376)
 .. got 5 bytes
read data
evbuffer_read 64 bytes (fd 376)
 .. got 64 bytes
read data
evbuffer_add (fd 376): 90 B
leastSize waiting for new data.
socket 376 write event (false)!
leastSize waiting for new data.
socket 376 read event!
evbuffer_read 5 bytes (fd 376)
 .. got 5 bytes
read data
evbuffer_read 240 bytes (fd 376)
 .. got 240 bytes
read data
EHLO response: 250-mx.google.com at your service, [83.69.213.227]
EHLO response: 250-SIZE 35882577
EHLO response: 250-8BITMIME
EHLO response: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN XOAUTH
EHLO response: 250-ENHANCEDSTATUSCODES
EHLO response: 250-PIPELINING
EHLO response: 250-CHUNKING
EHLO response: 250 SMTPUTF8
evbuffer_add (fd 376): 90 B
leastSize waiting for new data.
socket 376 write event (false)!
leastSize waiting for new data.
socket 376 read event!
evbuffer_read 5 bytes (fd 376)
 .. got 5 bytes
read data
evbuffer_read 48 bytes (fd 376)
 .. got 48 bytes
read data
evbuffer_add (fd 376): 106 B
leastSize waiting for new data.
socket 376 write event (false)!
leastSize waiting for new data.
socket 376 read event!
evbuffer_read 5 bytes (fd 376)
 .. got 5 bytes
read data
evbuffer_read 48 bytes (fd 376)
 .. got 48 bytes
read data
evbuffer_add (fd 376): 90 B
leastSize waiting for new data.
socket 376 write event (false)!
leastSize waiting for new data.
socket 376 read event!
evbuffer_read 5 bytes (fd 376)
 .. got 5 bytes
read data
evbuffer_read 192 bytes (fd 376)
 .. got 192 bytes
read data
TCP close request true open
Actively closing TCP connection
Closing socket 376...
...socket 376 closed.
object.Exception@C:\Users\bubenkov_di\AppData\Roaming\dub\packages\vibe-d-0.7.23
\source\vibe\mail\smtp.d(266): Expected status 235 in response to login password
, got 535:  5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 jr1s
m3534859lbc.43 - gsmtp
----------------
0x00413182 in pure @safe void std.exception.bailOut!(Exception).bailOut(immutabl
e(char)[], uint, const(char[])) at C:\D\dmd2\windows\bin\..\..\src\phobos\std\ex
ception.d(400)
0x00417DD6 in pure @safe bool std.exception.enforce!(Exception, bool).enforce(bo
ol, lazy const(char)[], immutable(char)[], uint) at C:\D\dmd2\windows\bin\..\..\
src\phobos\std\exception.d(352)
0x00428B8A in void vibe.mail.smtp.expectStatus(vibe.core.stream.InputStream, int
, immutable(char)[]) at C:\Users\bubenkov_di\AppData\Roaming\dub\packages\vibe-d
-0.7.23\source\vibe\mail\smtp.d(267)
0x004261AC in void vibe.mail.smtp.sendMail(vibe.mail.smtp.SMTPClientSettings, vi
be.mail.smtp.Mail) at C:\Users\bubenkov_di\AppData\Roaming\dub\packages\vibe-d-0
.7.23\source\vibe\mail\smtp.d(194)
0x004031B7 in _Dmain at D:\code\test\source\app.d(33)
0x004BC0D2 in D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv
0x004BC0A7 in void rt.dmain2._d_run_main(int, char**, extern (C) int function(ch
ar[][])*).runAll()
0x004BBFBF in _d_run_main
0x00425A80 in main
0x004F95C5 in mainCRTStartup
0x751F337A in BaseThreadInitThunk
0x775E92E2 in RtlInitializeExceptionChain
0x775E92B5 in RtlInitializeExceptionChain
Main thread exiting
Error executing command run:
Program exited with code 1

D:\code\test>

Re: Can't send e-mail

Am 19.05.2015 um 14:07 schrieb Suliman:

Expected status 235 in response to login password
, got 535: 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 jr1s
m3534859lbc.43 - gsmtp

Seems like the user name/password is wrong, or one of the other reasons
mentioned on that page.

Pages: 1 2