Answered by:
Sending Mails thru Microsoft Office 365

Question
-
What am I doing wrong
I am new to this and this code worked when we used zimbra hosed email but when I change the info for Office 365 nothing seem to work
The code I am using is below
Public Sub SendMail0(ByVal strEmail As String, ByVal strSubj As String, ByVal strBody As String)
Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort = 2
Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout = "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic = 1
Const cdoSendUserName = "http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword = "http://schemas.microsoft.com/cdo/configuration/sendpassword"
Const cdoSMTPUseSSL = "http://schemas.microsoft.com/cdo/configuration/smtpusessl"
Set objConfig = CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
With Fields
.Item(cdoSMTPServer) = "smtp.office365.com"
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServerPort) = 587
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "donotreply@xppower.com"
.Item(cdoSendPassword) = "********"
.Item(cdoSMTPUseSSL) = True
' .Item(cdoSendUsingMethod) = cdoSendUsingPort
' .Item(cdoSMTPServer) = "zimbrahostedemail.com"
' .Item(cdoSMTPServerPort) = 25
' .Item(cdoSMTPConnectionTimeout) = 10
' .Item(cdoSMTPAuthenticate) = cdoBasic
' .Item(cdoSendUserName) = "mailer@emcohv.com"
' .Item(cdoSendPassword) = "********"
.Update
End With
Set objmessage = CreateObject("CDO.Message")
With objmessage
.configuration = objConfig
.To = strEmail
.From = "donotreply@xppower.com"
.Subject = strSubj
.TextBody = "Do not reply: This email account is not monitored." & vbNewLine & vbNewLine & strBody
.send
End With
Set Fields = Nothing
Set objmessage = Nothing
Set objConfig = Nothing
End Sub
but I keep getting the following error message
"Run-time error '-2147220973(80040213)': The transport failed to connect to the server"
If I change the port to 25 I get the same error
If I comment out the cdoSMTPUseSSL and the .Item(cdoSMTPUseSSL) = True I get the following error
"Run-time error '-2147220978(8004020e)': The server rejects the sender address. The server response was: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM"
Please help
I have searched the internet with no avail and tried all different kinds of configurations
I feel like it is something really easy tat I am missing
- Edited by Pavel Celba Tuesday, February 16, 2016 10:36 PM -- " --
Tuesday, February 16, 2016 5:57 PM
Answers
-
Thank you so much Pavel
The way I got it to work FINALLY was to configure the email to direct send with port 25
it surprised me that I only had to change 2 lines of code
cdoSMTPServer and the port number
I have been banging my head for week trying to get this to work- Marked as answer by Herro wongMicrosoft contingent staff Monday, February 29, 2016 7:26 AM
Monday, February 22, 2016 7:09 PM
All replies
-
Yes, some clients do not work with Office365 SMTP. You should try to connect with the Telnet and check the server responses which can tell more. The easiest solution is to use another mail provider obviously.
The second error message could be related to this NOTE: When using Outlook365, if the "From Address" and "Auth Username" do not match, there is a potential need to configure "Send As" privileges for your mail server. Here is how you can configure this for Office365:http://support.microsoft.com/kb/2572646. You may also need to set up SMTP relay on your Office365 account.
More info: https://portal.smartertools.com/kb/a2862/smtp-settings-for-outlook365-and-gmail.aspx
This Technet article could also help: https://technet.microsoft.com/en-us/library/dn554323(v=exchg.150).aspx
- Edited by Pavel Celba Tuesday, February 16, 2016 10:49 PM links update
Tuesday, February 16, 2016 10:48 PM -
Thank you Pavel
I will look into your suggestions
- Edited by Pattaz_2000 Monday, February 22, 2016 4:00 PM
Monday, February 22, 2016 4:00 PM -
Thank you so much Pavel
The way I got it to work FINALLY was to configure the email to direct send with port 25
it surprised me that I only had to change 2 lines of code
cdoSMTPServer and the port number
I have been banging my head for week trying to get this to work- Marked as answer by Herro wongMicrosoft contingent staff Monday, February 29, 2016 7:26 AM
Monday, February 22, 2016 7:09 PM