The code works fine for me using my home smtp service as well as Google's gmail one (with TSL/SSL set). Other users have reported success. But for several others sending emails fail. I have tried a test program with users to verify this. If I compile identical code with 5.31, emails are sent but with newer ones they are not. An error is generated at the SendMail() function. I suspect an issue with the ISP but require a solution.
Any ideas?
Below is the test source code.
Code: Select all
;SendTestEmail.pb
InitNetwork()
Procedure.l SendEmail(EmailSmtpServer$,EmailPort,EmailUseSSL,EmailLogIn$,EmailPassword$,EmailSendFrom$,EmailSubject$,EmailSendBody$)
EmailResult.l=#False
If CreateMail(0,EmailSendFrom$,EmailSubject$,#PB_Ascii)=0
MessageRequester("Notice","CreateMail command failed")
ProcedureReturn EmailResult
EndIf
SetMailBody(0,EmailSendBody$)
AddMailRecipient(0,EmailSendTo$,#PB_Mail_To)
EmailFlag=1 ;#PB_Mail_Asynchronous 1
If EmailUseSSL
EmailFlag=3 ;#PB_Mail_Asynchronous | #PB_Mail_UseSSL 3
EndIf
If SendMail(0,EmailSmtpServer$,EmailPort,EmailFlag,EmailLogIn$,EmailPassword$)=0
MessageRequester("Notice","SendMail command failed")
ProcedureReturn EmailResult
EndIf
Repeat
Progress=MailProgress(0)
Delay(50)
Until Progress=#PB_Mail_Finished Or Progress=#PB_Mail_Error
FreeMail(0)
If Progress=#PB_Mail_Error
MessageRequester("Notice","Error during sending")
EndIf
If Progress=#PB_Mail_Finished
MessageRequester("Notice","Email sent")
EmailResult=#True
EndIf
ProcedureReturn EmailResult
EndProcedure
;Default email settings
;Replace with your own settings
EmailSmtpServer$="smtp.netspace.net.au"
EmailPort=25
EmailLogIn$="library@school.vic.edu.au"
EmailPassword$="library401"
EmailSendFrom$="library@school.vic.edu.au"
EmailSubject$="Test Email"
EmailUseSSL=0
EmailSendTo$="me@hotmail.com"
OW=OpenWindow(#PB_Any,0,0,580,460,"Test email",#PB_Window_TitleBar | #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WW=WindowWidth(OW):WH=WindowHeight(OW)
X=WW-81
Y=WH-29
CloseEvent=9
ButtonGadget(CloseEvent,X,Y,75,22,"Close")
AddKeyboardShortcut(OW,#PB_Shortcut_Escape,CloseEvent)
X=10
Y=40
W=110
X1=X+W+6
W1=400
H=24
SK=H+6
TextGadget(#PB_Any,X,Y+4,W,20,"SMTP server:",#PB_Text_Right)
SMTPSERVER=StringGadget(#PB_Any,X1,Y,W1,H,EmailSmtpServer$)
Y+SK
SSL=CheckBoxGadget(#PB_Any,X1,Y,W1,H,"Use TLS/SSL (email server must support this)")
SetGadgetState(SSL,EMAILSSL)
Y+SK
TextGadget(#PB_Any,X,Y+4,W,20,"Port:",#PB_Text_Right)
PORT=StringGadget(#PB_Any,X1,Y,40,H,Str(EmailPort))
Y+SK
TextGadget(#PB_Any,X,Y+4,W,20,"Email login:",#PB_Text_Right)
LOGIN=StringGadget(#PB_Any,X1,Y,W1,H,EmailLogIn$)
Y+SK
TextGadget(#PB_Any,X,Y+4,W,20,"Email password:",#PB_Text_Right)
PASSWORD=StringGadget(#PB_Any,X1,Y,W1,H,EmailPassword$)
Y+SK
TextGadget(#PB_Any,X,Y+4,W,20,"From email address:",#PB_Text_Right)
SENDFROM=StringGadget(#PB_Any,X1,Y,W1,H,EmailSendFrom$)
Y+SK
TextGadget(#PB_Any,X,Y+4,W,20,"Subject:",#PB_Text_Right)
SUBJECT=StringGadget(#PB_Any,X1,Y,W1,H,EmailSubject$)
Y+SK*2
TextGadget(#PB_Any,X,Y+4,W,20,"Send to:",#PB_Text_Right)
ST=StringGadget(#PB_Any,X1,Y,W1,24,EmailSendTo$)
Y+32
TextGadget(#PB_Any,X,Y+4,W,20,"Message:",#PB_Text_Right)
STB=StringGadget(#PB_Any,X1,Y,W1,H,EmailSubject$)
Y+SK
SendEmailButton=ButtonGadget(#PB_Any,X1,Y,100,22,"Send test email")
SetActiveGadget(SMTPSERVER)
Repeat
revent=WaitWindowEvent()
If revent=#PB_Event_Repaint Or revent=257 Or revent=275
Continue
EndIf
If revent=#PB_Event_Menu
event=EventMenu()
If event=CloseEvent
Break
EndIf
EndIf
If revent=#PB_Event_CloseWindow
Break
EndIf
If revent=#PB_Event_Gadget
event=EventGadget()
If event=CloseEvent
Break
EndIf
If event=SendEmailButton
EmailSmtpServer$=GetGadgetText(SMTPSERVER)
EmailUseSSL=GetGadgetState(SSL)
EmailPort=Val(GetGadgetText(PORT))
EmailLogIn$=GetGadgetText(LOGIN)
EmailPassword$=GetGadgetText(PASSWORD)
EmailSendFrom$=GetGadgetText(SENDFROM)
EmailSubject$=GetGadgetText(SUBJECT)
EmailSendTo$=GetGadgetText(ST)
EmailSendBody$=GetGadgetText(STB)
If Len(EmailSmtpServer$)=0
MessageRequester("Error","SMTP server not specified.")
SetActiveGadget(SMTPSERVER)
Continue
EndIf
If EmailPort=0
MessageRequester("Error","Email port not specified.")
SetActiveGadget(PORT)
Continue
EndIf
If Len(EmailSendBody$)=0
MessageRequester("Error","No text to send")
SetActiveGadget(STB)
Continue
EndIf
If Len(EmailSendTo$)=0
MessageRequester("Error","No recipient email address")
SetActiveGadget(ST)
Continue
EndIf
EmailSendBody$+Chr(13)+Chr(10)
SendEmail(EmailSmtpServer$,EmailPort,EmailUseSSL,EmailLogIn$,EmailPassword$,EmailSendFrom$,EmailSubject$,EmailSendBody$)
EndIf
EndIf
ForEver
CloseWindow(OW)
End
Code tags added
10.11.2016
RSBasic