FoxPro Programming
SMTP send using Office 365
Gravatar is a globally recognized avatar based on your email address. SMTP send using Office 365
  MarkB
  All
  Feb 22, 2021 @ 03:58pm

Using the following code I cannot seem to get anything to work using the smtp.office365.com SMTP server. The below code returns a "504 5.7.4 Unrecognized authentication type".

Following is a link to a article explaining the requirements (same article in many posts). https://www.unifeyed.com/portal/knowledgebase/16/How-do-I-use-Office365-for-SMTP.html

do wwSmtp
loSmtp = CREATEOBJECT("wwSmtp")
loSmtp.cMailServer = "smtp.office365.com"
loSmtp.cSenderEmail = "OfficeAdmin@xxx.org"
loSmtp.cSenderName  = "companyName - Department"
loSmtp.cUsername = 'OfficeAdmin@xxx.org'
loSmtp.cPassword = 'password'
loSmtp.lUseSsl = .T.
loSmtp.nServerPort=573
loSmtp.cLogfile = 'testmail.log'
loSmtp.cRecipient = 'me@xxx.com'
loSmtp.cSubject = 'smtp Send test'
loSmtp.cContentType = 'text/html'
loSmtp.cMessage = 'This is a test sending from smtp'
loSmtp.cAlternateContentType = "text/plain"
loSmtp.cAlternateText = "Plain text can go here."
IF !loSmtp.SendMail()
	wait window loSmtp.cErrorMsg
ELSE
	wait wind 'SENT'	
ENDIF

Using wwClient 6.0 tools, Windows 10, Foxpro 9 I have tried many variations of the above code without success. Hopefully someone else has gotten this to work.

Gravatar is a globally recognized avatar based on your email address. re: SMTP send using Office 365
  Rick Strahl
  MarkB
  Feb 22, 2021 @ 05:10pm

Make sure nMailMode is set to 0. It should be set to .NET Mail Mode.

Defaults have changed at some point and offhand I'm not sure if .NET mode is the default.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: SMTP send using Office 365
  Steve Howie
  Rick Strahl
  Mar 4, 2021 @ 06:46am

HI there, I'm having the same problem with Office365. I do not have 2 factor auth setup and the account is setup for authenticated SMTP. My sample code looks nearly identical to above, but just in case...

Do wwsmtp.prg
oSMTP = Createobject("wwSmtp")

oSMTP.nMailMode = 0
oSMTP.cMailServer = "smtp.office365.com"		&&:587"
oSMTP.nServerPort = 587
oSMTP.lUseSSL = .T.

oSMTP.cusername = "myuser@mydomain.com"
oSMTP.cpassword = "mypassword"

oSMTP.cSenderName = "Me"
oSMTP.cSenderEmail = "myuser@mydomain.com"

oSMTP.cRecipient = "myothertestuser@myotherdomain.com"
oSMTP.cSubject = "Test"
oSMTP.cMessage = "Test at " + Ttoc(Datetime())

oSMTP.cContentType = "text/html"

llresult = oSMTP.sendmail()
If llresult
	Messagebox("Message sent successfully.",0+64)
Else
	Messagebox(oSMTP.cerrormsg,0+48)
Endif

Again, with two different accounts on two different outlook365 domains, this times out. Any help would be greatly appreciated!

Peace,

Steve

Gravatar is a globally recognized avatar based on your email address. re: SMTP send using Office 365
  Steve Howie
  Steve Howie
  Mar 4, 2021 @ 09:33am

Just a bit more testing... I was able to successfully send through the original account with .net smtp connector, so the account seems to be working ok:

Imports System.Net.Mail

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim smtpClient As New SmtpClient("smtp.office365.com")
        smtpClient.Port = 587
        smtpClient.Credentials = New Net.NetworkCredential("tech@xxxxx", "xxxxxxxxx")
        smtpClient.EnableSsl = True

        smtpClient.Send("tech@xxxxxxx", "showie@xxxxxxxxxx", "test message 1", "Here is the body of the email")


    End Sub
Gravatar is a globally recognized avatar based on your email address. re: SMTP send using Office 365
  Steve Howie
  Steve Howie
  Mar 4, 2021 @ 02:49pm

OK, I figured out my problem, which was that I've used various West Wind tools over the years and had some outdated DLL's floating around, apparently.

I've cleaned everything up and am able to send e-mail now; sorry for the spam (no pun intended) on the thread!

Peace,

Steve

Gravatar is a globally recognized avatar based on your email address. re: SMTP send using Office 365
  Rick Strahl
  Steve Howie
  Mar 4, 2021 @ 09:20pm

Good to hear.

Yeah, if it works in .NET then it should definitely also work with wwSmtp since it uses the same components.

+++ Rick ---

© 1996-2024