Archived Forum Post

Index of archived forum posts

Question:

Problem sending eMail with Office365 SMTP

Aug 10 '16 at 11:40

I can't send email if i use Office 365 account. I have the same problem if i use sTunnel....I can only use it only with Gmail account. Can anyone help me ?

The code i use is this:

LOCAL loMailman
LOCAL lnSuccess, lcSuccess
LOCAL loEmail
Local lcMessage

lcMessage = ""
*  The mailman object is used for sending and receiving email.
loMailman = CreateObject('Chilkat_9_5_0.MailMan')

*  Any string argument automatically begins the 30-day trial.
lnSuccess = loMailman.UnlockComponent("myCode")
IF (lnSuccess <> 1) THEN
    ? loMailman.LastErrorText
    RELEASE loMailman
ENDIF

*  Set the SMTP server to Office365's SMTP server.
*  Note: Please be sure to double-check the SMTP settings
*  with your provider or with the official Office365 documentation
*  provided by Microsoft.  The required settings could change...
loMailman.SmtpHost = "smtp.office365.com"
loMailman.SmtpPort = 587
loMailman.StartTLS = 1
loMailman.SmtpSSL  = 0

*  Set the SMTP login/password
loMailman.SmtpUsername = "myMail"
loMailman.SmtpPassword = "myPassword"

*  Create a new email object
loEmail = CreateObject('Chilkat_9_5_0.Email')

loEmail.Subject = This.xSubject
If !Empty(This.xHtmlBody)
    loEmail.SetHtmlBody(This.xHtmlBody)
Else
    loEmail.Body = This.xBody
Endif
loEmail.From = This.xFrom
lnSuccess = loEmail.AddMultipleTo("Test@test.com)
lnSuccess = loEmail.AddMultipleCC("")
lnSuccess = loEmail.AddMultipleBCC("")

For ii=1 To Alen(This.xFiles,1)
    lcFile = This.xFiles[ii,1]
    If !Empty(lcFile) And File(lcFile)
        lcSuccess = loEmail.AddFileAttachment(lcFile)
    Endif
EndFor

lnSuccess = loMailman.SendEmail(loEmail)
IF (lnSuccess <> 1) THEN
    lcMessage = loMailman.LastErrorText
ENDIF

Answer

Information about what transpired in any given Chilkat method call is always available in the LastErrorText property. If the mailman.SendEmail call failed, then immediately after (but prior to calling any other method on the same Chilkat object instance), examine the contents of the mailman.LastErrorText property. It will provide information about what happened -- and this can be used to answer questions, or to know what questions to ask.

(In general, when debugging, the 1st question to be asked is "What information sources exist to find out more about what happened?" In this case, you can examine the reference documentation to see that LastErrorText is always as source of information. You'll also find there's an SmtpSessionLog property.)


Answer

I updated my chilkat control and now it works