Sending SMTP Mail Via Office 365 Exchange Using CDO
Sending SMTP Mail Via Office 365 Exchange Using CDO
(http://clicpharmacodebits.files.wordpress.com/2012/07/image.png)
Now click on the hyperlink marked Settings for POP, IMAP, and SMTP access
(http://clicpharmacodebits.files.wordpress.com/2012/07/image1.png)
and you will get a window with the server and port settings. Something like:
Server name: podxxxxx.outlook.com
Port: 587
Encryption method: TLS
2. External Applications
If you are using applications that have their own emailing engine such as Final Builder, Telerik Test
Studio, TFS, etc.
Most likely you will be able to fill in the above information easily something like:
(http://clicpharmacodebits.files.wordpress.com/2012/07/image2.png)
Its important to notice that we need to Authenticate and use SSL and enter our user credentials
3. CDO.Message
Sending email using CDO.Message is (for reasons unknown to me slightly different). I use VB Script
from a Windows 2008 server as follows:
1
2
3
4
5
6
7
8
9
10
11
Dim objCDO
Set objCDO = CreateObject("CDO.Message")
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configur
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configur
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configur
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configur
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configur
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configur
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configur
objCDO.Configuration.Fields.Update
' Rest of sending code goes here...
Please note here that the port is not 587 but 25. Do not understand why this works but it does. If you
can explain it please let me know.
Reply
Telmo Silva says:
March 5, 2013 at 09:01
I think that means there is no mail server on the other end so things to check are: IP address,
port # and any mail proxy settings or SSL settings (since the port # will be different).
Reply
Lenin Avila says:
March 5, 2013 at 18:10
Hi Telmo,
I solved the problem, it seems the problem is in the network of the company, to test the
application on an external network (eg from home), the program does work.
Have you ever had this kind of problem?
Anyway thank you very much for your help.
Have a good day
regards,
Lenin
4. aylinksahin says:
February 21, 2013 at 08:08
Hi,
i try it on my remote server but i took an error : 424 Object required
here is my code can you help me pls?
Dim ObjSendMail
Dim cdoConfig
Dim Fields As ADODB.Fields
Set cdoConfig = CreateObject(CDO.Configuration)
Set Fields = cdoConfig.Fields
This section provides the configuration information for the remote SMTP server.
With Fields
.Item(http://schemas.microsoft.com/cdo/configuration/sendusing) = 2
.Item(http://schemas.microsoft.com/cdo/configuration/smtpserver) = pod51017.outlook.com
.Item(http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout) = 30
.Item(http://schemas.microsoft.com/cdo/configuration/smtpserverport) = 25
.Item(http://schemas.microsoft.com/cdo/configuration/smtpauthenticate) = 1
.Item(http://schemas.microsoft.com/cdo/configuration/sendusername) =
[email protected]
.Item(http://schemas.microsoft.com/cdo/configuration/sendpassword)= Tedk123
.Item(http://schemas.microsoft.com/cdo/configuration/smtpusessl) = False
.Update
End With
End remote SMTP server configuration section==
strHTML =
strHTML = strHTML &
strHTML = strHTML &
strHTML = strHTML & This is the test HTML message body
strHTML = strHTML &
strHTML = strHTML &
Set ObjSendMail = CreateObject(CDO.Message)
Set ObjSendMail.Configuration = cdoConfig
With ObjSendMail
.To = [email protected] ToDo: Enter a valid email address.
.From = [email protected] ToDo: Enter a valid email address.
.Subject = This is a test CDOSYS message (Sent via Port 25)
.HTMLBody = strHTML
on error resume next
cdoMessage.Send
if Err.Number 0 then
response.Write Email send failed: & Err.Number & - & Err.Description &&vbcrlf
end if
.Send
End With
Reply
Telmo Silva says:
February 21, 2013 at 09:23
Look at the line where you cdoMessage.Send
What is cdoMessage? Where do you define it ?
Reply
5. naztri says:
February 7, 2013 at 18:15
Hi I have this script and I stopped working when migrating to Office365 can help me thanks
Dim objPectraOBPI
Set objPectraOBPI = CreateObject(PectraOBPI.Engine)
objCDO.Configuration.Fields(http://schemas.microsoft.com/cdo/configuration/smtpserver) =
pod51018.outlook.com
objCDO.Configuration.Fields(http://schemas.microsoft.com/cdo/configuration/sendusing) = 2
objCDO.Configuration.Fields(http://schemas.microsoft.com/cdo/configuration/smtpserverport) =
25
objCDO.Configuration.Fields(http://schemas.microsoft.com/cdo/configuration/sendusername) =
[email protected]
objCDO.Configuration.Fields(http://schemas.microsoft.com/cdo/configuration/sendpassword) =
ejemplo
objCDO.Configuration.Fields(http://schemas.microsoft.com/cdo/configuration/smtpauthenticate)
=1
objCDO.Configuration.Fields(http://schemas.microsoft.com/cdo/configuration/smtpusessl) = true
objCDO.To = [email protected]
objCDO.CC = DirMail
objCDO.From = [email protected]
objCDO.BCC = [email protected]
objCDO.Subject = Disponibilidad (OV: & OVSucComprobante & - & OVnro & ) Productor:
& OVNroCta & - & OVProductor
objCDO.HTMLBody = comm2
objCDO.Send
Set objCDO = Nothing
MsgBox (Correo Enviado)
Reply
naztri says:
February 8, 2013 at 19:40
Lo solucione solo me faltaba
objCDO.Configuration.Fields.Update
thanks
Reply
6. Najam Ahmed says:
January 4, 2013 at 13:31
Great article Telmo! I spent the entire day wondering why my script kept giving me the 530 5.7.1
authentication error. Just came across your post and changed the port to 25. Not sure why this is so
but it works! Thanks!
Reply
Telmo Silva says:
January 4, 2013 at 13:58
Great to hear it helps. If you ever come across the reason why CDO is different let us know!
Reply
7. Andrew K says:
August 26, 2012 at 17:10
I just cant get this to work any thoughts?
ObjSendMail.Configuration.Fields.Item
(http://schemas.microsoft.com/cdo/configuration/sendusing) = 2 Send the message using the
network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item
(http://schemas.microsoft.com/cdo/configuration/smtpserver) =pod51018.outlook.com
ObjSendMail.Configuration.Fields.Item
(http://schemas.microsoft.com/cdo/configuration/smtpserverport) = 25
ObjSendMail.Configuration.Fields.Item
(http://schemas.microsoft.com/cdo/configuration/smtpusessl) = true Use SSL for the connection
(True or False)
ObjSendMail.Configuration.Fields.Item
(http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout) = 60
If your server requires outgoing authentication uncomment the lines bleow and use a valid email
address and password.
ObjSendMail.Configuration.Fields.Item
(http://schemas.microsoft.com/cdo/configuration/smtpauthenticate) = 1 basic (clear-text)
authentication
ObjSendMail.Configuration.Fields.Item
(http://schemas.microsoft.com/cdo/configuration/sendusername) [email protected]
ObjSendMail.Configuration.Fields.Item
(http://schemas.microsoft.com/cdo/configuration/sendpassword) =xxxxx
ObjSendMail.Configuration.Fields.Update
Reply
Telmo Silva says:
August 27, 2012 at 10:28
Not unless you share some more info such as environment, error message, etc. the code looks ok
at first glance.
Reply