Mail problems

BlitzPlus Forums/BlitzPlus Programming/Mail problems

Starwar(Posted 2007) [#1]
Hi.
I use this code (see code archives). But the mail did arrive at me. Using other mailfunction does not help. They all show: Mail sent. Any idea whatīs wrong?
EDIT: The server does not need POP login first.

t=OpenTCPStream( "smtp.1und1.de",25 )
If Not t RuntimeError( "Error connecting" )
WriteLine t,"EHLO BlitzMail" ;<------------I changed HELO to this because of Error 550
WriteLine t,"MAIL FROM: XXX@..."
WriteLine t,"RCPT TO: XXX@..."
WriteLine t,"DATA"
WriteLine t,"Hello there Mark!"
WriteLine t,"This is from Blitz Mail!"
WriteLine t,""
WriteLine t,"."
WriteLine t,"QUIT"
CloseTCPStream (t)
Print "Done. Press any key...":WaitKey



Ked(Posted 2007) [#2]
This code will not work. Use BlitzMail Deluxe (code archives) to actually send the mail.


Starwar(Posted 2007) [#3]
I tried BlitzzMail and other Mailers already. They donīt dunction :ī(.


xlsior(Posted 2007) [#4]
A couple of things:

1) If you send out through your ISP's email server and you try to send to a user at a different ISP, then it's quite likely that your provider requires you to use SMTP Authentication before it will accept mail for delivery from you. Look up the RFC's on how to implement authentication, because if they require it then it's never going to work without it unless you connect directly to the mailserver of the recipient of the email. Which would require you to query the MX record out of the DNS fto find the destination server, AND only works if the destination server doesn't blacklist email originating on a dialup/cable/dsl IP address like many do

2) You should wait after the EHLO and some of the other headers for the server to return the message that it's ready first -- if you simply cram down all the other text, then it might very well ignore it.

3) Also: After the DATA statement you should put the email headers. the mail from: and receipt to: lines are the envelope headers, not the message headers. the from: and to: listed in your email program are the ones AFTER the DATA statement. If you leave them out, many mailservers will simply consider your message spam and trash it.

The proper order:

<connect to mailserver>
(wait for 2xx statement)
EHLO blitzmail (try EHLO first -- if it fails (error 550) THEN fall back to using HELO)
(wait for 2xx code)
MAIL FROM: sender@domain
(wait for 2xx code)
RCPT TO: recipient@domain
(wait for 2xx code)
DATA
(wait for 2xx/3xx code)
FROM: "bob user" <sender@domain>
TO: "joe user" <recipient@domain>
SUBJECT: "Subject Line"
<blank line>
First line of email
Second line of email
<blank>
. (period)
(wait for 2xx code)
QUIT


Starwar(Posted 2007) [#5]
I canīt belive it:

AppTitle "Mail"
Global com
Print popaccountlogin ("pop.1und1.de\",\"lukas-maeusezahl@...","*******")
Print send$(\"smtp.1und1.de\",50,\"Lukas\",\"lukas-maeusezahl@online.de\",\"Lukas\",\"lukas-maeusezahl@...")
Print popaccountlogout()
WaitKey 


;--------------------------------------------------
;MailSender
;--------------------------------------------------
Function send$(server$,timeout%,mailfromname$,mailfrom$,toname$,mailto$,sub$)
sm = OpenTCPStream (server$,25)
If sm = 0 Then Return "-ERR Could not connect"
;Say EHLO
WriteLine sm,"EHLO Mailer"
Delay timeout%
r$ = ReadLine (sm)
If Left(r$,1) <> 2 Then Return "-ERR EHLO failed: "+r$
DebugLog "+OK Server says: " + r$
WriteLine sm,"AUTH LOGIN"
ReadLine (sm)
;Senderīs name
WriteLine sm,"MAIL FROM: "+mailfromname$
Delay timeout%
r$ = ReadLine (sm)
If Left(r$,1) <> 2 Then Return "-ERR "+r$
DebugLog "+OK Server says: " + r$
;RCTP
WriteLine sm,"RCTP TO: "+mailto$
Delay timeout%
r$ = ReadLine (sm)
If Left(r$,1) <> 2 Then Return "-ERR "+r$
DebugLog "+OK Server says: " + r$
;DATA
WriteLine sm,"DATA"
Delay timeout%
r$ = ReadLine (sm)
If Left(r$,1) <> 2 And Left(r$,1) <> 3 Then Return "-ERR "+r$
DebugLog "+OK Server says: " + r$
WriteLine sm,"DATE: " + CurrentDate$ ()
WriteLine sm, "X-MAILER: Outlook"
WriteLine sm,"FROM: "+mailfromname$+" <"+mailfrom$+">"
WriteLine sm,"TO: " + toname$+" <"+mailto$+">"
WriteLine sm,"SUBJECT: "+sub$
WriteLine sm,""
WriteLine sm,"TRON"
WriteLine sm,""
WriteLine sm,"."
Delay timeout%
r$ = ReadLine (sm)
If Left(r$,1) <> 2 Then Return "-ERR "+r$
DebugLog "+OK Server says: " + r$
WriteLine sm,"QUIT"
r$ = ReadLine (sm)
If Left(r$,1) <> 2 Then Return "-ERR "+r$
DebugLog "+OK Server says: " + r$
CloseTCPStream sm
Return "+OK "+r$
End Function 




Function popAccountLogout$()
	WriteLine com, "QUIT" ; Disconnect-Commando
	r$ = ReadLine(com) ; Get Returnstring
	If Mid(r$, 1, 3) = "+OK" Then Return "+OK disconnected: " + r$
	If Mid(r$, 1, 4) = "-ERR" Then Return "-ERR not disconnected: "+r$
End Function



Function popAccountLogin$(server$, user$, pass$)
com = OpenTCPStream(server$, 110)
If com = 0 Then
  Return "-ERR connection failed"
Else
  i$ = ReadLine(com) ; Intercept the greeting
  WriteLine com, "USER " + user$
  i$ = ReadLine(com)
  If Mid(i$, 1, 1) = "-" Then
    Return "-ERR no such user: "  +i$
  Else
    WriteLine com, "PASS " + pass$
    i$ = ReadLine(com)
    If Mid(i$, 1, 1) = "-" Then
      Return "-ERR password wrong: "+i$
    Else
      Return "+OK logged in: " + i$
    EndIf
  EndIf
EndIf

It doesnt work!
Last answer from the server: 250-SIZE
Any more ideas? Iīm depressived!


xlsior(Posted 2007) [#6]
250-SIZE is just one of the (optional) eSMTP informational responses, letting the client know the maximum permitted message size. if there is no value specified, then it means that ther is no global message size limit.
(alternatively, you could see something like 250-SIZE=1048576 which would give you a 1MB limit)

Have you tried manually connecting to the mailserver and running through the list of commands?

Simply open a command prompt, and type:

telnet mailservername 25

which should give you the welcome message.
Then type: EHLO computername, and simply follow the same list of commands that you want your program to send.

That way you can see if there are any weird delays in the reponses and other things that look odd. One thing though: Some mailserver have very tight timings. The godaddy smtp server for example will kill the connection if it doesn't get the strings in a couple of seconds, which means that it's near impossible to deliver a message 'by hand' over telnet like this... But for most servers it works fine.