Secure SMTP

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Secure SMTP

Sebastia Van Lacke
Hi, I want to send e-mails using the gmail smtp server. I understand that google only accepts secure connections. Is it possible to use SendMail to do this?

Sebastian


sebastian van lacke | web developer caesar systems | see clearly. decide smarter.

[hidden email] | t: +1.281.598.8790 | t: +54.11.4389.0126 | petrovr.blogspot.com | www.caesarsystems.com 

This message and any attached documents contain information from Caesar Systems LLC that may be confidential/trade secret and/or privileged. If you are not the intended recipient, you may not read, copy, distribute or use this information. If you have received this transmission in error, please notify the sender immediately by telephone or by reply e-mail and then delete this message.


Reply | Threaded
Open this post in threaded view
|

Re: Secure SMTP

EstebanLM
you need to use stunnel (or something like that) to redirect your mail through it 

cheers,
Esteban

El 28/06/2011, a las 12:18p.m., Sebastian Van Lacke escribió:

Hi, I want to send e-mails using the gmail smtp server. I understand that google only accepts secure connections. Is it possible to use SendMail to do this?

Sebastian


sebastian van lacke | web developer caesar systems | see clearly. decide smarter.

[hidden email] | t: +1.281.598.8790 | t: +54.11.4389.0126 | petrovr.blogspot.com | www.caesarsystems.com 

This message and any attached documents contain information from Caesar Systems LLC that may be confidential/trade secret and/or privileged. If you are not the intended recipient, you may not read, copy, distribute or use this information. If you have received this transmission in error, please notify the sender immediately by telephone or by reply e-mail and then delete this message.



Reply | Threaded
Open this post in threaded view
|

Re: Secure SMTP

Nick
In reply to this post by Sebastia Van Lacke
Hi Sebastian,

Hi, I want to send e-mails using the gmail smtp server. I understand that google only accepts secure connections. Is it possible to use SendMail to do this?

As Esteban mentioned on getitmade.com we're doing precisely that - using our google account to send the mail. Here's our configuration:

1) You need to add WAEmailConfiguration as a configuration ancestor.
And you need to add this configuration:

SMTP Server = localhost
SMTP Port = 259
SMTP Server user name = <your account, for example [hidden email]>
SMTP Server password = <your account password>

2) You send mails with this string:

GRPlatform current
       seasideDeliverEmailMessage: ((WAEmailMessage
               from: (WAEmailAddress address: '[hidden email]')
                       to: (WAEmailAddress address:  '[hidden email]')
                       subject: 'test')
               body: (WAStringEmailBody string: 'a test')).

it works inside the application (inside a session)... not outside (see below)

3) You need an stunnel installed and running. In ubuntu, you need to change:

a) replace stunnel.conf with:

client = yes
debug = debug

[smtps]
accept = 127.0.0.1:259
connect = smtp.gmail.com:465

b) create  /etc/stunnel/stunnel.pem

openssl req -new -x509 -days 3650 -nodes -out stunnel.pem -keyout stunnel.pem

c) enable running:

/etc/init.d/stunnel4

ENABLED=1

/etc/default/stunnel4

ENABLED=1

d) restart:

sudo /etc/init.d/stunnel4 restart


If you want to send the mail outside the session for example on a service task you need a mock request context then use something like:


WACurrentRequestContext
use: IZMockCurrentRequestContext 
during: [ 
GRPlatform current
       seasideDeliverEmailMessage: ((WAEmailMessage
               from: (WAEmailAddress address: '[hidden email]')
                       to: (WAEmailAddress address:  toEmailAddress)
                       subject: aSubject)
               body: (WAStringEmailBody string: aBody)) ]


You'll also need at least version SMTPMail-NickAger.9  you can grab it from the attachment on this bug report http://code.google.com/p/glassdb/issues/detail?id=248 (I don't have permission to check it into the repository ... anyone)
Reply | Threaded
Open this post in threaded view
|

Re: Secure SMTP

Nick
Just be even more explicit:


1) You need to add WAEmailConfiguration as a configuration ancestor.
And you need to add this configuration:

SMTP Server = localhost
SMTP Port = 259
SMTP Server user name = <your account, for example [hidden email]>
SMTP Server password = <your account password>

In code this would read something like:

app configuration addParent: WAEmailConfiguration instance.
app 
preferenceAt: #smtpServer put: 'localhost';
preferenceAt: #smtpPort put: 259;
preferenceAt: #smtpUsername put: '[hidden email]';
preferenceAt: #smtpPassword put: 'Rea11yS3cur3'.    "that isn't our password!"
Reply | Threaded
Open this post in threaded view
|

Re: Secure SMTP

Sebastia Van Lacke
In reply to this post by Sebastia Van Lacke
Hi, thanks for your help.

I created the tunnel with Stunnel as Esteban suggested, and it works out when sending e-mails from Pharo but not from Gemstone. What is strange is that if I send an email debugging the code, the connection succeeds and the e-mail is sent, but, if I do it by evaluating the code, it fails.

I am testing it by evaluating this:

| client server mail username password|
   
    username := '[hidden email]'.
    password := 'xxxx'.
    client := SendMail new.
    client user: username.
    client password: password.
    server := 'smtp.lalala.com'.
    client
        mailhostName: server;
        smtpPort: 5000;
        [hidden email]' ;
        to: '[hidden email]';
        subject: 'From Gemstone through Stunnel';
        text: 'It works!'.
    client send

Note: I have loaded SMTPMail-NickAger.9.mcz

Any idea about what could be happening?

Sebastian
Reply | Threaded
Open this post in threaded view
|

Re: Secure SMTP

Sebastia Van Lacke
I still have this problem connecting to the tunnel. Are you using it successfully?

On debugging "SendMail >> send" message I have notice this:

openTcpConnection
        | ok |
        ok := self connectTo: self smtpPort on: self mailhostName.
        ok ifFalse: [self close].
        ^ok

This method answers true only when I am debugging. Running the code in only one step answers false.

Internally this method calls to #_twoArgPrim: opcode with: arg1 with: arg2

with opcode = 2 arg1 = hostname arg2 = smtpPort

and returns nil


Any help may be of use

thanks!

Sebastian