Autore Topic: Invio email  (Letto 1654 volte)

Offline milio

  • Senatore Gambero
  • ******
  • Post: 1.273
  • Chi parla poco dice tanto...
    • Mostra profilo
Invio email
« il: 18 Marzo 2013, 18:58:12 »
Ciao a tutti.

In questi giorni ho provato il componente gb.net.smtp con scarsi risultati, allora mi sono messo 'a studiare' e ho realizzato una piccola classe per inviare mail con un terminale Telnet.

Volevo pero' sapere secondo voi, se l'oggetto Socket di gambas poteva in qualche modo sostituire Telnet per la comunicazione con il server smtp.

Ho fatto un paio di prove, ma mi ritorna solamente l'output di collegamento al server

220 posta.hextra.it Service ready

e poi e' come se si scollegasse  :-\ ... avete avuto esperienze simili?


Offline pastrank

  • Maestro Gambero
  • ****
  • Post: 266
    • Mostra profilo
Re: Invio email
« Risposta #1 il: 18 Marzo 2013, 20:49:21 »
e poi e' come se si scollegasse  :-\ ... avete avuto esperienze simili?

Ma dopo che mostri il messaggio 220, che fai? A quel punto, se non sbaglio, dovresti passare un MAIL FROM, e poi ci sarebbe (non e' detto volerlo attendere, ricordo) la risposta 250 da parte del server...

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.332
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Invio email
« Risposta #2 il: 18 Marzo 2013, 20:57:51 »
Caro milio, un uccellino mi ha riferito che la buona anina  :angel: di un ormai defunto Ambasciatore, per aiutarti, pare abbia posto la questione anche nella M.L.I.
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline milio

  • Senatore Gambero
  • ******
  • Post: 1.273
  • Chi parla poco dice tanto...
    • Mostra profilo
Re: Invio email
« Risposta #3 il: 18 Marzo 2013, 21:26:18 »
@pastrano

Si, il mio server vuole l'autenticazione prima, ma come avevo scritto, dopo l'output di connessione e' come se rimanesse in un limbo, finche' il server non va in timeout... bho

@vuott

Ti chiameremo ghost rider :)... grazie per l'interessamento

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.332
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Invio email
« Risposta #4 il: 19 Marzo 2013, 00:45:46 »
Caro milio,

dalla M.L.I. - per ora - vi sono due risposte (te le riporto in lingua originale).

Una è di tale Willy Raets:
« What seems to be the problem as I have no trouble sending mail using
gb,net.smtp

This is an example directly from one of my projects.
Note that info is retrieved from setting on a mail preferences form
where user can set the values and they are saved as settings.

Nore: All settings are string values from settings file using
gb.settings.
Settings["mail/from"] = yourmail@yourprovider.org
Settings["mail/smtp"] = smtp.yourprovider.org
Settings["mail/port"] = 25

DefaultMail is a Public String variable I use to provide my own mail
address.
I use this routine for error trapping and having error info send back to
me automatically if Mail Preferences are set.

It works like a charm..

Private Sub SendMail(TextToSend As String, Subject As String)
 
  Dim hMail As New SmtpClient
  hMail.To.Add(DefaultMail)
  hMail.From = Settings["mail/from"]
  hMail.Host = Settings["mail/smtp"]
  hMail.Port = Settings["mail/port"]
  'If Settings["mail/tsl"] = -1 Then
  '  hMail.Encrypt = 2
  'Else
    hMail.Encrypt = 0
  'Endif
  hMail.Subject = Subject
  hMail.Add(TextToSend)
  hMail.Send
  MailSend = True

End

I commented out the encryption as I don't get it to work. But that is
not a Gambas problem as my regular (non Gambas mail client) can't send
SSL or TSL either.

Hope this can help your friend

--
Kind regards,

Willy (aka gbWilly)
»


L'altra è di Minisini in persona (...che chiede maggiori delucidazioni sul problema riscontrato):
« Which version of Gambas does he use? What does he want to do exactly
with gb.net.smtp? Which problems did he encounter? Where is the code?

--
Benoît Minisini
»


Non so se vuoi rispondere tu direttamente (sarebbe meglio),  :-\ o... se devo chiamare l'uccellino.  ;D
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.332
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Invio email
« Risposta #5 il: 19 Marzo 2013, 11:41:19 »
L'uccellino mi ha portato un'altra risposta di aiuto dalla M.L.I.:

« #!/usr/bin/env gbs3


USE "gb.db", "gb.net.smtp"

Private hcon As New Connection
Private hTim as Timer
Public Sub Main()
  Application.Daemon = True
  hTim = new timer as "Timer1"
  hTim.Delay = 60000
hTim.Trigger()
  hTim.Start
End

Public sub Timer1_Timer()
  Dim hsmtp As Smtpclient
  Dim hResMails As Result
  Dim s As String

  'Définir la connection
  hcon.type = "mysql"
  hCon.host = "localhost"
  hcon.login = "#######"
  hCon.password = "*******"
  hcon.name = "GF"

  hResMails = db.exec("SELECT * FROM emails")

  For Each hResMails
    hsmtp = New SmtpClient
    hsmtp.Host = "mail.toile-libre.org"
    hsmtp.User = "gf_info@gambasforge.org"
    hsmtp.Password = "*******"
    hsmtp.Port = 587
    hsmtp.From = hsmtp.User

    For Each s In Split(hResMails!to)
        hsmtp.To.Add(s)
    Next
    For Each s In Split(hResMails!cc)
      hsmtp.Cc.Add(s)
    Next
    For Each s In Split(hResMails!bcc)
      hsmtp.bcc.Add(s)
    Next
    hsmtp.Subject = iif(hResMails!sujet, hResMails!sujet, "nosubject")
    hsmtp.Add(hResMails!message, "text/plain")
    if hResMails!message_html Then hsmtp.Add(hResMails!message_html,
"text/html")
    hsmtp.Send()
  Next
  If hResMails.count = 0 Then Return
  hResMails.MoveLast()
  db.Exec("DELETE FROM emails WHERE id<=&1", hResMails!id)

Catch
    File.Save(User.Home &/ "mailerror.log", Format(Now(), GB.GeneralDate) &
": \n" & Error.Backtrace.Join("\n") & " " & Error.Text & " " & Error.Where
& "\n")


End

This is the mail deamon of gambasforge, it work since more than one year
without fail nor reboot. It control the db every 1 min. The page refresh is
more quick :-)

A good Script example too :-)

Fabien Bodard
»
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline milio

  • Senatore Gambero
  • ******
  • Post: 1.273
  • Chi parla poco dice tanto...
    • Mostra profilo
Re: Invio email
« Risposta #6 il: 19 Marzo 2013, 17:20:45 »
Porca vacca... adesso ci riprovo... grazie delle dritte :)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.332
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Invio email
« Risposta #7 il: 19 Marzo 2013, 17:53:40 »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline milio

  • Senatore Gambero
  • ******
  • Post: 1.273
  • Chi parla poco dice tanto...
    • Mostra profilo
Re: Invio email
« Risposta #8 il: 19 Marzo 2013, 18:08:52 »
 ;D dove le trovi tu ste gif....

Comunque forse ho capito dov'e' il problema: il tipo di autenticazione

Ci sono tre tipi di autenticazione: PLAIN, LOGIN e CRAM-MD5

Il server smtp da cui cerco di mandare le email non supporta l'autenticazione di tipo PLAIN, infatti mi da errore 504:

AUTH PLAIN
504 Command parameter not implemented


Da guida su componente:

_SmtpClient.Password (gb.net.smtp)
  Property Password As String

  Return or set the password used for authentication.

  Only PLAIN authentication is supported at the moment.


Quindi chiudo la discussione con un [NON RISOLTO] ? che dite? :)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.332
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Invio email
« Risposta #9 il: 19 Marzo 2013, 21:17:56 »
Volevo chiederti una cosa:
se hai comunque scritto del codice anche tenendo conto di quanto suggerito dagli interventi dei due membri della MLI, puoi inserire qui almeno la sola parte di codice che hai scritto per l'invio dell'email ?  :coder:
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline milio

  • Senatore Gambero
  • ******
  • Post: 1.273
  • Chi parla poco dice tanto...
    • Mostra profilo
Re: Invio email
« Risposta #10 il: 19 Marzo 2013, 23:02:01 »
solo una premessa:

.Password (TelnetSMTP)
  Property Password As String

  Return or set the password used for authentication.

  Only LOGIN authentication is supported at the moment.


 ;D

Ecco i sorgenti
« Ultima modifica: 19 Marzo 2013, 23:08:56 da milio »

Offline pastrank

  • Maestro Gambero
  • ****
  • Post: 266
    • Mostra profilo
Re: Invio email
« Risposta #11 il: 19 Marzo 2013, 23:59:05 »
Ecco i sorgenti

Sara' un problema con l'autentificazione? Lo posso provare velocemente solo senza, ma in quel modo funziona, con il mio smtp server.

Offline milio

  • Senatore Gambero
  • ******
  • Post: 1.273
  • Chi parla poco dice tanto...
    • Mostra profilo
Re: Invio email
« Risposta #12 il: 20 Marzo 2013, 00:08:33 »
Eccoti proprio te volevo :)

Tu che hai gia' masticato l'argomento, sapresti dirmi come si 'costruisce' l'autenticazione PLAIN (che leggendo in giro su internet si da in pasto al server lo user e password nella medesima stringa con BASE64 encoding) e sopratutto il flamigerato CRAM-MD5 ?

Hai qualche link sull'argomento?

Offline pastrank

  • Maestro Gambero
  • ****
  • Post: 266
    • Mostra profilo
Re: Invio email
« Risposta #13 il: 20 Marzo 2013, 01:32:16 »
Tu che hai gia' masticato l'argomento, sapresti dirmi come si 'costruisce' l'autenticazione PLAIN (che leggendo in giro su internet si da in pasto al server lo user e password nella medesima stringa con BASE64 encoding) e sopratutto il flamigerato CRAM-MD5 ?

Fai conto che pur avendo avuto qualche esperienza, e' vecchia di parecchi anni: ai tempi scrissi un olr/newsreader (uno dei 3-4 programmi che non mi sono vergognato a fare vedere agli altri, circa 40000 righe di codice), ma era nel periodo tra vb3 e vb6!  Comunque, a occhio dovresti guardare - ma le avrai gia' viste - rfc 2104, 2554 e 2195, e (magari non ti e' gia' venuto in mente), prova a fare una googlata con cram md5 vb: ad esempio, qui http://forums.codeguru.com/showthread.php?189137-Cram-md5 mi sembra di vedere qualcosa di interessante, ma esempi con Visual Basic ne trovi diversi.
Per la PLAIN, sembra illuminante questo, invece http://www.fehcom.de/qmail/smtpauth.html

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.332
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Invio email
« Risposta #14 il: 13 Agosto 2013, 15:55:26 »
Aggiungo qui un intervento scritto nella M.L.I. riguardo alll'invio di e-mail con il componente gb.net.smtp:


" Well... it simply didn't send the mails, or more specific: the mails
never arrived anywhere, and I couldn't make out any error messages
anywhere. The only message I got was the ending "-> quit". During my
holidays, it might have been caused by a bad internet connection, but it
wouldn't run here either.

Maybe you remember, you told me to look in the "standard errors", but I
didn't find anything at /var/log...

Then this weekend I found a discussion from last year or so you had had
with someone on the SMTP topic, and it turned out you could not find a
way to complete programming. In the documentation it says "not
everything is supported yet". So I looked for another way of
implementing it.

Here is my test project which was intended to be included into the
bigger main project once it had been running. My personal data have been
changed:

Public Sub Main()
Dim t$ As String
Dim email As New SmtpClient

   t$ = File.Load(Application.Path &/ "test.pdf")

   With email
     .Add("This is the mail text")
     .Add(t$, mime.Binary, "test.pdf")
     .To.Add("eilert-sprachen@t-online.de")
     .From = "myname@web.de"
     .Subject = "Ein Test"
     .Encrypt = Net.SSL
     .Port = 587
     .Host = "smtp.web.de"
     .User = "username"
     .Password = "password"
     .Debug = True
   End With

   Try email.Send

   If Error Then
     Print Error.Text
     Print Error.Where
   Endif

End


I tried this with my yahoo account and t-online account (= German
Telecom), sending mails forth and back, but to no avail.

When I tried sendEmail giving it the same data, the mail was sent at once.

Rolf
"


" A little food for thought....

I am not sure about Yahoo or Google over seas but here in the US Google for
sure, and I believe Yahoo both will not accept mail from a home server. I
used to run my own mail servers and still do but with the limitation that I
cannot send mail to Google without having a paid Google account for each
domain. Google and many free mail suppliers did this to combat spam. I have
not tried in a year or so to send from any of my domains that do not have a
paid google account attached. So if they reversed this, I am unaware.

Randall Morgan
"


" Yes, not from a server (MTA), but from an e-mail client like
Thunderbird, an MUA. So I tried to use yahoo and the others as MTA.

Eilert
"
« Ultima modifica: 13 Agosto 2013, 19:34:04 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »