Just tested this one again here, still works fine.
Code: Select all
Procedure EmailMessage()
;
If InitNetwork() <> 0
;
MailToUser.s = "eatworms@gmail.com"
MailToSubject.s = "PureBasic 5.40, Beta 3, TLS Authentication test"
MailToBody.s = "Yo, Bozo, wot yu sending utter crap to yourself for ya twit???"
;
HumanName.s = "Underpants"
ServerName.s = "smtp.gmail.com"
PortNumber.i = 587 ; Old port was 465
UserName.s = "Underpants"
Password.s = "wotsmepassword"
EmailAddress.s = "Underpants@gmail.com"
;
If HumanName.s And ServerName.s And PortNumber.i And UserName.s And Password.s And EmailAddress.s
;
If MailToUser.s And MailToSubject.s And MailToBody.s
;
OutgoingMailId.i = CreateMail(#PB_Any, EmailAddress.s, MailToSubject.s)
;
If OutgoingMailId.i
;
SetMailBody(OutgoingMailId.i, MailToBody.s)
;
AddMailRecipient(OutgoingMailId.i, MailToUser.s, #PB_Mail_To)
;
If SendMail(OutgoingMailId.i, ServerName.s, PortNumber.i, #PB_Mail_Asynchronous | #PB_Mail_UseSSL, UserName.s, Password.s)
;
Repeat
ProgressId.i = MailProgress(OutgoingMailId.i)
If ProgressId.i = #PB_Mail_Connected
Debug "Connected to the email server."
ElseIf ProgressId.i = #PB_Mail_Error
ErrorCounter.i + 1
Debug "Error connecting and sending message."
Else
Debug "Sent " + Str(ProgressId.i) + " bytes of this email."
EndIf
Delay(300)
Until ProgressId.i = #PB_Mail_Finished Or Progress.i = #PB_Mail_Error Or ErrorCounter.i = 20
;
If ProgressId.i = #PB_Mail_Finished
Debug "Email message packet correctly sent."
ElseIf ProgressId.i = #PB_Mail_Error
Debug "Email message packet could not be sent."
EndIf
;
Else
Debug "The mail packet could not be sent."
EndIf
;
Else
Debug "Could not create the outgoing email packet."
EndIf
;
Else
Debug "One or more of the recipient's details are empty."
EndIf
;
Else
Debug "One or more of the email server details are empty."
EndIf
;
Else
Debug "Could not initialise the network environment to send mail"
EndIf
;
EndProcedure
EmailMessage()
And lifting this one straight out of the manual for attachments and forgot that google blocks any mention of 7'zip, zip, log. bat' etc so renamed attachment to .moo and it worked as well.
Code: Select all
If InitNetwork() <> 0
If CreateMail(0, "underpants@gmail.com", "Hello !")
SetMailBody(0, "Hello !" + #CRLF$ + "This is a multi-" + #CRLF$ + "line mail !")
AddMailAttachment(0, "Underpants !" , "C:\Users\bangf\Downloads\Downloaded stuff\diffuse.moo")
; Change the recipients to real one
AddMailRecipient(0, "eatworms@gmail.com", #PB_Mail_To)
; Set the SMTP server to use
; Result.i = SendMail(0, "smtp.gmail.com", 587, #PB_Mail_Asynchronous, "underpants", "mepassword")
Result = SendMail(0, "smtp.gmail.com", 587, #PB_Mail_Asynchronous | #PB_Mail_UseSSL, "underpants", "mepassword")
Repeat
Progress.i = MailProgress(0)
; I added this section to see if anything was happening
If ProgressId.i = #PB_Mail_Connected
Debug "Connected to the email server."
ElseIf ProgressId.i = #PB_Mail_Error
ErrorCounter.i + 1
Debug "Error connecting and sending message."
Else
Debug "Sent " + Str(ProgressId.i) + " bytes of this email."
EndIf
; End of my added section
Delay(300)
Until Progress.i = #PB_Mail_Finished Or Progress.i = #PB_Mail_Error Or ErrorCounter.i = 40
If Progress = #PB_Mail_Finished
Debug "--------------------------------------------------------------------------------"
Debug "Information: - Mail correctly sent !"
Else
Debug "--------------------------------------------------------------------------------"
Debug "Error: - Can't send the email !"
EndIf
EndIf
Else
Debug "--------------------------------------------------------------------------------"
Debug "Error: - Cannot initialise the network environment !"
EndIf