Вы находитесь на странице: 1из 10

ClicData Blog

Dashboards made easy

Sending SMTP mail via Office 365 exchange using


CDO.Message and other applications
This entry was posted on July 13, 2012 by Telmo Silva, in Technical and tagged BPOS, CDO.Message,
email, Office 365, outlook, SMTP, VBScript. Bookmark the permalink. 14 Comments
We love Office 365, specifically the Exchange/Outlook email features such as calendar sharing, etc.
But when we switched to it most of our automated email applications and scripts failed as the SMTP
(and POP) configurations are different.
So here are my findings on the subject in the hope that it can help some people.

1. Obtain SMTP Configuration Parameters


First get the parameters of your Office 365 account by going to Office 365 live
(https://portal.microsoftonline.com/ (https://portal.microsoftonline.com/)) login and access Outlook
Then access the Options menu See All Options

(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.

14 thoughts on Sending SMTP mail via Office 365


exchange using CDO.Message and other applications
1. James Shimell says:

August 29, 2013 at 12:24


Great Article, this has massively helped me to send mails from my application through the
Microsoft Online servers. Thank you very much!!
Reply
2. Pavlo says:
March 24, 2013 at 18:22
Does not work for Office365 for me.. The combination port25+TLS shows transport failed error.
Also, MS does not say that CDO.Message supports TLS:
http://msdn.microsoft.com/en-us/library/ms526318(v=exchg.10).aspx
The only working solution that I was able to find, is the one using SMTPProxy:
http://community.office365.com/en-us/forums/158/t/18581.aspx
Id rather not install any extra software, but looks like this is the only way so far..
Im on MS Access 2010
Reply
Telmo Silva says:
March 25, 2013 at 06:35
Hi Pavlo,
Sorry you are having issues. The script has described and the settings still work for us here at
ClicData. So perhaps it is a difference between our accounts.
I checked the links you sent and noticed an error or two on their example scripts. For example
on one script the spelled smtperver and not smtpserver so if you copied and pasted their script
take a look and see if there are no silly errors like that.
Best of luck!
Reply
3. Lenin Avilaila says:
March 4, 2013 at 22:02
Hi, Telmo,
Congratulations for your article.
Please with your help.
I have a next message:
The transport failed to connect server.
Password, User, Server, all is ok.
What do you think?

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) =

insankaynaklari@tedankara.k12.tr
.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 = aylink@tedankara.k12.tr ToDo: Enter a valid email address.
.From = insankaynaklari@tedankara.k12.tr 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)

Dim objCDO As CDO.Message


Set objCDO = CreateObject(CDO.Message)
Dim OVnro, OVSucursal, DirMail, OVProductor, OVNroCta
OVnro = objPectraObpi.AttributeGetValue(TrxId, OVNumero, )
OVSucursal = objPectraObpi.AttributeGetValue(TrxId, OVSucComprobante, )
DirMail = objPectraObpi.AttributeGetValue(TrxId, OVUMail, )
OVProductor = objPectraObpi.AttributeGetValue(TrxId, OVRazonSocial, )
OVNroCta = objPectraObpi.AttributeGetValue(TrxId, OVNroCta, )
actividad = Stock
comm2 =
comm2 = comm2 &
comm2 = comm2 & Proceso
comm2 = comm2 &
comm2 = comm2 &
comm2 = comm2 &
comm2 = comm2 &
comm2 = comm2 & Proceso Autorizacion de Ordenes de Venta
comm2 = comm2 &
comm2 = comm2 &
comm2 = comm2 &
comm2 = comm2 & La Orden de venta N: & OVSucursal & - & OVnro
comm2 = comm2 & , de la entidad & OVNroCta & - & OVProductor & no supero la
& actividad & .
comm2 = comm2 &
comm2 = comm2 &
comm2 = comm2 & Para procesar la OV ingrese a
comm2 = comm2 & <a
comm2 = comm2 &
comm2 = comm2 &
comm2 = comm2 &
comm2 = comm2 &
comm2 = comm2 &
comm2 = comm2 &
comm2 = comm2 &
comm2 = comm2 &
comm2 = comm2 &
comm2 = comm2 &
Dim cmd, Server, WshShell, BD, usr, pass, RbtMailfrom
Set oNode = Nothing

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) =
ejemple@ejemplo.com
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 = ejemo@ejemp.com
objCDO.CC = DirMail
objCDO.From = ejempl@ejemplo.com
objCDO.BCC = ejemplo@ejemplo.com
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) =automation@xxxx.com
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

Blog at WordPress.com. Customized Fresh & Clean Theme.


Follow

Follow ClicData Blog


Powered by WordPress.com