Autore Topic: Invio email: errori con SMTP Client  (Letto 4017 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.683
  • Ne mors quidem nos iunget
    • Mostra profilo
Invio email: errori con SMTP Client
« il: 20 Agosto 2013, 19:41:59 »
Riporto questa discussoine apparsa nella M.L.I.:


" I'm using gb.smpt to send email from a Gambas routine. The routine is:

Codice: gambas [Seleziona]
12 Public Sub btnSend_Click()
13
14  Dim t$ As String
15      Dim email As New SmtpClient
16
17      t$ = File.Load("/home/marty/Test.txt")
18
19      With email
20        .Add("Hello")
21        .Add(t$, Mime.Default, "Test.txt")
22        .To.Add("xxxxxx@xxxx.xxx")
23        .From = "xxxxxx@xxxx.xxx"
24        .Subject = "Linux Test"
25        .Encrypt = Net.SSL
26        .Port = 465
27        .Host = "smtp.xxxx.com"
28        .User = "xxxxxxx@xxxx.xxx"
29        .Password = "password"
30        .Debug = True
31     End With
32
33      email.Send()

End

Sensitive data removed. There are multiple errors:

1. If I include the line to add an attachment -"Cannot find Mime subtype in line 33"

2.If I use Net.SSL with port 465  "Error 535 Authentication failed"
     My account should use SSL and port 465. That's the way it is set up on Windows.
     Debug output:
<- 220 relay01.dlls.pa.xxxxxxx.net ESMTP Postfix

-> ehlo marty-xxxxxxxxxxxxxxxxxxxx

<- 250-relay01.dlls.pa.xxxxx.net
250-PIPELINING
250-SIZE 36350634
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN

-> auth plain AG1tY2cyOTQ0MEBmcm9udGllci5jb20AOTA2NlBvDQo=

<- 535 5.7.8 Error: authentication failed: authentication failure

-> quit

No matter what I try the message is not sent. The docs say that V 3.4 supports encryption.
Can you  tell me where I'm going wrong? I'm running Ubuntu 12.04. Is it
possible that SSL is not installed? How can I check it? Then how to install it?

Thanks for your patience and help!

Marty
"


" Not a spontaneous help, but as you will see in this list, I have had the
same or a similar problem with it during the last weeks. At least I can
say that I got no error with the Mime. thing, but I had a pdf to attach
and used Mime.Binary (no idea if that was correct, but there were no
complaints).

I tried with different providers and their different settings. With SSL,
I got no message at all, just ->quit. With TLS I got the same kind of
errors and found no way to solve them. That provider uses STARTTLS,
maybe it's not been fully implemented yet.

Eventually I used an external tool for sending the mails.

Regards
Rolf
"
« 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.683
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Invio email: errori con SMTP Client
« Risposta #1 il: 20 Agosto 2013, 22:23:21 »
...continua...


" That is because in the .add you need to use a string for mime type.
Mime.binary will return an integer value.

@ Marty
For text file write .Add(t$, "text/plain","Test.txt")
Assuming that t$ is a File.Load of a text file

@ Rolf
For pfd file write .Add(t$, "application/pdf","Test.pdf")
Assuming that t$ is a File.Load of a pdf file

> I tried with different providers and their different settings. With SSL,
> I got no message at all, just ->quit. With TLS I got the same kind of
> errors and found no way to solve them. That provider uses STARTTLS,
> maybe it's not been fully implemented yet.
>
> Eventually I used an external tool for sending the mails.


Over here in the Netherlands you have to use the smtp server of the
provider that is connecting you.
So at home I have one, going to my girlfriend I need to change my mail
client settings to her providers smtp server. At work I need to change
my mail client settings to that providers smtp server.

Hence all you need here is the smtp DNS name or IP, no username nor
password of the provider that is connecting you at that location.
So I can't help you with the SSl or TSL.

I can only say that I built a Gambas application at work that uses both
gb.smpt and gb.cairo (for pdf making). It sends information on extra
worked hours of personel to the accountants in a mail containing a
general text in the body and custom signature and an attached pdf
containing the information on extra hours for personel.

gb.cairo makes the pdf, next gb.smtp sends it all. I put a Wait 0.1 in
between to make sure pdf is complete before sending all.
Works like a charm.

--
Kind regards,

Willy
"


" Thank you for that tip, I've changed it accordingly. So "Test.pdf" just
gives a random name to be added to the data in the string, and it
doesn't need the path?

> Over here in the Netherlands you have to use the smtp server of the
> provider that is connecting you.


We can do the same here, but you could also use any other provider's
access like Yahoo, GMX etc. I tried them all, no success.

> I can only say that I built a Gambas application at work that uses both
> gb.smpt and gb.cairo (for pdf making). It sends information on extra
> worked hours of personel to the accountants in a mail containing a
> general text in the body and custom signature and an attached pdf
> containing the information on extra hours for personel.


Yes, this is pretty near to what I intend to do with my Gambas app.

> gb.cairo makes the pdf, next gb.smtp sends it all. I put a Wait 0.1 in
> between to make sure pdf is complete before sending all.
> Works like a charm.


According to Benoit, Cairo works synchroneously, at least he is pretty
sure it does. But it turned out this wasn't my problem.

Except SMTP sending, it works great here too.

Thanks again for the advice!

Rolf
"
« Ultima modifica: 21 Agosto 2013, 09:26:16 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. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.683
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Invio email: errori con SMTP Client
« Risposta #2 il: 21 Agosto 2013, 09:28:56 »
...continua...


" Thanks, Willy. The change from mime.Text to "text/Plain cured the Mime
error. I still get the authentication error: error 535 - 5.7.8. I've tried
to send emails to accounts located on the same server. No mail sent. Tried
setting gb.smpt to the same parameters as my wife's account. Her account
works with no encryption and port 25 in window Outlook but, fails with
gb.smpt. Same error 535. See routine below.



Dim t$ As String

> 15      Dim email As New SmtpClient

> 16

> 17      t$ = File.Load("/home/marty/Test.txt")

> 18

> 19      With email

> 20        .Add("Hello")

> 21        .Add(t$, Text/Plain, "Test.txt")

> 22        .To.Add("xxxxxx@xxxx.xxx")

> 23        .From = "xxxxxx@xxxx.xxx"

> 24        .Subject = "Linux Test"

> 25        .Encrypt = Net.None

> 26        .Port = 25

> 27        .Host = "smtp.xxxx.com"

> 28        .User = "xxxxxxx@xxxx.xxx"

> 29        .Password = "password"

> 30        .Debug = True

> 31     End With

> 32

> 33      email.Send()

 
Marty McGlensey
"
« 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.683
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Invio email: errori con SMTP Client
« Risposta #3 il: 21 Agosto 2013, 16:08:10 »
...continua...


" The 3rd argument in Add() is the name the attachment will get when
attached in the mail. You can use the same name as the original file you
would like to add (no need for the path) or make up a new name for the
attachement

> > Over here in the Netherlands you have to use the smtp server of the
> > provider that is connecting you.
>
> We can do the same here, but you could also use any other provider's
> access like Yahoo, GMX etc. I tried them all, no success.


Have you tried with only server and port settings, no username, no
password, no SSL or TSL.

Willy
"


" Here is the code of a routine I use in one of my applications.

Some notes to make it understandable:
1. Some of the information used comes from a selection in a Combobox
(mail from), some TextBoxes (mail to, mail subject) and some TextAreas
(mail Add for both body and attachment)
2. The Bugreport.MakeErrorSendFile() in Catch is a routine somewhere
else handling my error reporting, so I know what goes wrong and where.
3. MailSend in a Public Boolean used elsewhere in the application to
give users an indication if mail send successfully or not.

-----------------------------------------

Codice: gambas [Seleziona]
Private Sub SendMail()
 
  Dim hMail As New SmtpClient
  hMail.Port = 25
  hMail.Host = "smtp.xxxx.xxx"
  hMail.Bcc.Add("xxxx@xxxx.xxx")
  hMail.From = cmbxFrom.Text
  hMail.To.Add(tbxTo.Text)
  hMail.Subject = tbxSubject.Text
  hMail.Add(txaBody.Text,, "")
  hMail.Add(txaAttachment.Text, "text/plain", "BijlageMailMinMax.txt")
  hMail.Send
  MailSend = True
 
  Catch
    MailSend = False
    BugReport.MakeErrorSendFile(Error.Code, Error.Text, Error.Where)
    Error.Clear
 
End

-----------------------------------------

As you see I only use port and host, no User or password, no encrypt.
Maybe the error occurs in the authentication part, don't know as I never
used authentication combined with smtp in any of my applications.
Willy
"


" I think I know why gb.smtp does not work. I have been getting the 535
error (authentication failed). I have tried everything including Rolf's
suggestion of leaving off the user and password. Still authentication
fails. Looking at the documentation for password and user it says that
only plain authentication is supported. I think the send process breaks
down when the password and user get to the smtp host. It may be looking
for an SSL encoded string not a plain string; therefore authentication
fails. Rolf and Willy let me know what you think. Is this possible?
Could openSSL be at fault? That's the other thought I had.

Rolf I've tried the routine you suggested and it seems to work. I may
follow your advice and use it.

Regards,
Marty
"


" You need to make sure that your smtp server does NOT require
authentication. If so there is NO need for user, password and encryption
and you should get NO authentication error.

If your smtp server DOES require user and password, leaving user and
password out will lead to an authentication failure (as it requires
authentication at server side)

Fact that you get the errors means gb.net.smtp does communicate with
smtp server, as these errors codes are generated by smtp server (giving
you the reason what goes wrong).

I cut this piece out of an earlier post you wrote:

> 2.If I use Net.SSL with port 465  "Error 535 Authentication
>        Debug output:
> <- 220 relay01.dlls.pa.xxxxxxx.net ESMTP Postfix
>
> -> ehlo marty-xxxxxxxxxxxxxxxxxxxx
>
> <- 250-relay01.dlls.pa.xxxxx.net
> 250-PIPELINING
> 250-SIZE 36350634
> 250-ETRN
> 250-AUTH LOGIN PLAIN
> 250-AUTH=LOGIN PLAIN
> 250-ENHANCEDSTATUSCODES
> 250-8BITMIME
> 250 DSN
>
> -> auth plain AG1tY2cyOTQ0MEBmcm9udGllci5jb20AOTA2NlBvDQo=
>
> <- 535 5.7.8 Error: authentication failed: authentication failure
>
> -> quit


See the line 250-AUTH LOGIN PLAIN and 250-AUTH=LOGIN PLAIN.
Seems like even when using SSL user and password is passed as plain text
and thus refused by smtp server leading to an authentication failure.
So seems documentation is correct on plain text password being passed.

Leaving user, password and encryption out will only work if smtp server
allows access without authentication (as explained above).

> Rolf I've tried the routine you suggested and it seems to work. I may
> follow your advice and use it.


Have you been having private mails as I wonder about the routine or are
you mixing up names (Rolf <-> Willy) and mean the routine I posted?
Because if so, feel free to use.

--
Kind regards,

Willy
"
« Ultima modifica: 22 Agosto 2013, 04:09:14 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. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.683
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Invio email: errori con SMTP Client
« Risposta #4 il: 22 Agosto 2013, 20:45:00 »
...continua...


" > error (authentication failed). I have tried everything including Rolf's
> suggestion of leaving off the user and password. Still authentication


That was Willy's suggestion, and it's only possible when you're directly
connected to the provider. When you want to use another provider, they
will insist on you having a name/password for authentication to avoid
spammers.

> fails. Looking at the documentation for password and user it says that
> only plain authentication is supported. I think the send process breaks
> down when the password and user get to the smtp host. It may be looking
> for an SSL encoded string not a plain string; therefore authentication
> fails. Rolf and Willy let me know what you think. Is this possible?
> Could openSSL be at fault? That's the other thought I had.


Actually, that brings back to my mind an idea I had last week. If we
could produce a string that is what name/password would be in SSL and
store it and send it instead, such as


Codice: gambas [Seleziona]
sUser = File.Load(Path &/ "encryptedString.user")
sPass = File.Load(Path &/ "encryptedString.pass")


and with SMTP client:

Codice: gambas [Seleziona]

.User = sUser
.Password = sPass


could that work? I don't know what the SSL function does with these
values, and if it runs anyway. If I was to make a guess, the answer
would be NO just because the SSL part should mingle these two strings
and build ONE single string out of them, so pre-building them would
produce mere garbage.

On my machines (both at home and in the office), SSL returns no messages
at all, only TLS returns error messages. So it might be, SSL isn't
started properly or even isn't started at all. Is there a way to find
out? One of my providers (my main provider) uses STARTTLS (which in my
understanding is a special variation of TLS), and there is no hint in
the docu whether Gambas supports this or not.

Rolf
"
« 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. »