About using CDO to send email within Excel

Hello Excel Experts:

Urgent help is required from you IT guys. I need to send emails
silently within Excel using VBA, and the following code doesn't work
for me (the code is found from PaulSadowski.com):

Sub Mail_Small_Text_CDO()
   Dim iMsg As Object
   Dim iConf As Object
   Dim strbody As String
   Dim Flds As Variant

   Set iMsg = CreateObject("CDO.Message")
   Set iConf = CreateObject("CDO.Configuration")

       iConf.Load -1    ' CDO Source Defaults
       Set Flds = iConf.Fields
       With Flds
           .Item("http://schemas.microsoft.com/cdo/configuration/
sendusing") = 2
           .Item("http://schemas.microsoft.com/cdo/configuration/
smtpauthenticate") = cdoBasic
           .Item("http://schemas.microsoft.com/cdo/configuration/
smtpserver") = "smtp.gmail.com"
           .Item("http://schemas.microsoft.com/cdo/configuration/
sendusername") = "meiwr9@gmail.com"
           .Item("http://schemas.microsoft.com/cdo/configuration/
sendpassword") = "mypassword"
           .Item("http://schemas.microsoft.com/cdo/configuration/
smtpserverport") = 465
           .Item("http://schemas.microsoft.com/cdo/configuration/
smtpusessl") = True
           .Item("http://schemas.microsoft.com/cdo/configuration/
smtpconnectiontimeout") = 60

           .Update
       End With
       'flds.Fields("urn:schemas:httpmail:importance") = 2
       'flds.Fields("urn:schemas:mailheader:X-Priority") = 1
       Flds.Update

   strbody = "Hi there: testing from CDO" & vbNewLine & vbNewLine & _
             "This is line 1" & vbNewLine & _
             "This is line 2" & vbNewLine & _
             "This is line 3" & vbNewLine & _
             "This is line 4"

   With iMsg
       Set .Configuration = iConf
       .To = "meiwr9@yahoo.com"
       .CC = ""
       .BCC = ""
       .From = "Steineke"
       .Subject = "Important message from Excel CDO"
       .TextBody = strbody
       .Send
   End With

   Set iMsg = Nothing
   Set iConf = Nothing
End Sub

The intention of above sub is to compose an email and send it from
Gmail SMTP server through Excel VBA to my yahoo's email account. The
Excel workbook is running in a machine which is connected to internet
via either dial up or intranet connection, but without any email
client program installed (at least we don't care). The fwllowing error
code is displayed when .send is executed:

Run-time error '-2147220973(80040213)':
The transport failed to connect to the server.

I do have a gmail account and a yahoo account. I checked gmail help
about how to set the settings for sending and receiving emails. The
computer is connected to internet occasionally through dial-up
connection, and we want the VBA to send an email with some data back
to the headquarter without much intervention of human beings.

How to get it work? I'm not a good programmer with some knowledge
about VB. Your comments are highly appreciated.

Ken

0
meiwr9 (1)
6/7/2007 1:33:47 PM
excel 39879 articles. 2 followers. Follow

1 Replies
569 Views

Similar Articles

[PageSpeed] 56

You have a reply at one of your other posts.

meiwr9@gmail.com wrote:
> 
> Hello Excel Experts:
> 
> Urgent help is required from you IT guys. I need to send emails
> silently within Excel using VBA, and the following code doesn't work
> for me (the code is found from PaulSadowski.com):
> 
> Sub Mail_Small_Text_CDO()
>    Dim iMsg As Object
>    Dim iConf As Object
>    Dim strbody As String
>    Dim Flds As Variant
> 
>    Set iMsg = CreateObject("CDO.Message")
>    Set iConf = CreateObject("CDO.Configuration")
> 
>        iConf.Load -1    ' CDO Source Defaults
>        Set Flds = iConf.Fields
>        With Flds
>            .Item("http://schemas.microsoft.com/cdo/configuration/
> sendusing") = 2
>            .Item("http://schemas.microsoft.com/cdo/configuration/
> smtpauthenticate") = cdoBasic
>            .Item("http://schemas.microsoft.com/cdo/configuration/
> smtpserver") = "smtp.gmail.com"
>            .Item("http://schemas.microsoft.com/cdo/configuration/
> sendusername") = "meiwr9@gmail.com"
>            .Item("http://schemas.microsoft.com/cdo/configuration/
> sendpassword") = "mypassword"
>            .Item("http://schemas.microsoft.com/cdo/configuration/
> smtpserverport") = 465
>            .Item("http://schemas.microsoft.com/cdo/configuration/
> smtpusessl") = True
>            .Item("http://schemas.microsoft.com/cdo/configuration/
> smtpconnectiontimeout") = 60
> 
>            .Update
>        End With
>        'flds.Fields("urn:schemas:httpmail:importance") = 2
>        'flds.Fields("urn:schemas:mailheader:X-Priority") = 1
>        Flds.Update
> 
>    strbody = "Hi there: testing from CDO" & vbNewLine & vbNewLine & _
>              "This is line 1" & vbNewLine & _
>              "This is line 2" & vbNewLine & _
>              "This is line 3" & vbNewLine & _
>              "This is line 4"
> 
>    With iMsg
>        Set .Configuration = iConf
>        .To = "meiwr9@yahoo.com"
>        .CC = ""
>        .BCC = ""
>        .From = "Steineke"
>        .Subject = "Important message from Excel CDO"
>        .TextBody = strbody
>        .Send
>    End With
> 
>    Set iMsg = Nothing
>    Set iConf = Nothing
> End Sub
> 
> The intention of above sub is to compose an email and send it from
> Gmail SMTP server through Excel VBA to my yahoo's email account. The
> Excel workbook is running in a machine which is connected to internet
> via either dial up or intranet connection, but without any email
> client program installed (at least we don't care). The fwllowing error
> code is displayed when .send is executed:
> 
> Run-time error '-2147220973(80040213)':
> The transport failed to connect to the server.
> 
> I do have a gmail account and a yahoo account. I checked gmail help
> about how to set the settings for sending and receiving emails. The
> computer is connected to internet occasionally through dial-up
> connection, and we want the VBA to send an email with some data back
> to the headquarter without much intervention of human beings.
> 
> How to get it work? I'm not a good programmer with some knowledge
> about VB. Your comments are highly appreciated.
> 
> Ken

-- 

Dave Peterson
0
petersod (12005)
6/7/2007 2:02:08 PM
Reply:

Similar Artilces:

Some Emails Cannot be Delivered
I have a problem that I cannot put a handle on with my exchange server. Some outbound messages do not reach their destination. The problem happens with certain destinations. However the confusing part is that some messages are able to make it through. This would mean that there are no problems with DNS or MX lookup or any connectivity issue since some emails manage to make it through. I'm at a loss and can't figure where to look first I hope that someone might have an idea. You'll have to provide more information. Are you receiving NDrs if so can you share them? Is ther...

Attaching Contacts to new email
Creating a new email. When contacts folder has "shared" contacts and "personal" contacts how can you set your personal contacts as the default? Example: creating a new email having never addressed the "send to" contact before, you hit the "To" button. Currently my "shared" contacts opens up but I would like my "personal" contacts page to open instead of having to drop down to "contacts" to bring up that list. Is there a solution to this? Thank you!!! On 2/26/2010 10:21 AM, assistantneedshelp wrote: >...

Looking for Excel Help
I'm a very novice Excel user and am looking for a little help with creating a formula for a spreadsheet I'm creating for my personal use. I would appreciate some assistance if possible. Thanks in advance. Dan --- Message posted from http://www.ExcelForum.com/ Hi Dan! Post a sample of what you want to do. Your question is just a tad open ended <g> -- Regards Norman Harker MVP (Excel) Sydney, Australia njharker@optusnet.com.au Excel and Word Function Lists (Classifications, Syntax and Arguments) available free to good homes. "DanB4105" <DanB4105.ywtpa@excelfor...

New to excel
Hi All, I'm new to Excel ( and to this forum :) ) and so I hope somebody may b able to help me. I've got 2 questions.... QUESTION 1 I've got a spreadsheet which takes data from one worksheet and uses i to calculate data in a second worksheet using the following code formula: =IF('4th November 2005'!B19="","nothing here dude",IF(B19<'4th Novembe 2005'!B19,"UP",IF(B19='4th November 2005'!B19,"Same",IF(B19>'4t November 2005'!B19,"DOWN")))) The problem is, when I create a new worksheet I have...

Recieving email with nothing in them? Blank??
From time to time, I will recieve email from friends, family, or business...and when I get the email, I open it up to find nothing but white space. I can't find a common thing between emails. I just know it is very frustrating when I have to ask people to resend the email to me or to a new address. When I look at my mail on the server, it is fine. It is when I open Outlook and it downloads it to my desktop. I get nothing. Any ideas? Cheers.. vg Sorry, wanted to add that I am using OL2003 with WINXP and everything is updated SP wise. I am starting to see some articles on this...

invalid email address
In message to Candy FH Muffman wrote of having an invalid email address. I use hotmail but would like to prevent ti being used by spammers. Is there any way I can hide it or restrict it in some way? Can I make it invalid? Thank you You mean when posting to an online service like this? Sure, don't type your (correct) email address. See my address or from many others to see an example. Note: I've removed your valid address in my reply. -- Robert Sparnaaij [MVP-Outlook] Coauthor, Configuring Microsoft Outlook 2003 http://www.howto-outlook.com/ Outlook FAQ, HowTo, Downloads, Add...

Formula without using numbers after decimal in the answer
I have a formula that derives the answer from a figure with a decimal. I don't want to use the figures after the decimal. Is there a way to just use the whole number and omit the numbers after the decimal without having to manually key in all these numbers manually? Thanks, Mustang You can use the INT function. This 'rounds down' any number to th nearest integer, e.g. if A1=2.567, a formula in B2 of =INT(A1) return 2 HTH Bruc -- swatsp0 ----------------------------------------------------------------------- swatsp0p's Profile: http://www.excelforum.com/member.php?...

Using Relative path for XML data file?
Is there a way to specify a relative path to an XML data file imported into Excel 2003? I am writing a web app that generates report data as XML for the user to download to their local machine. This data is to be consumed by an Excel reporting spreadsheet, which contains display-formatted tables and charts that are mapped to various data fields in an XML Map, which is in turn linked to the xml data file they will download. The idea is the user only needs to download the data for updates, not the whole spreadsheet. However, since I cannot predict the path where the user will store their...

Sorting emails by domains, from org to edu (right char is the most significant)
Hello All I need to sort the domains according their emails. For example: Before sorting: john1@abc.edu john3@abc.org john5@abc.com john4@bcd.org john2@bcd.edu john6@bcd.com After sorting: john3@abc.org john4@bcd.org john5@abc.com john6@bcd.com john1@abc.edu john2@bcd.edu That is, how to sort, according to the domain name ( the right is the most significant )? Thanks. Z. D. On Feb 15, 11:09 pm, "duzhid...@gmail.com" <duzhid...@gmail.com> wrote: > That is, how to sort, according to the domain name ( the right is the > most significant )? you'll probably need ...

Excel button problem
Hi All I have a macro that copies a worksheet in the active workbook and puts it into a new workbook - then formats it and deletes any buttons on the worksheet. On the first click on the button the macro works ok. On the second click, it fails because the all assigned macros on all buttons in the active workbook changed from "mba" to "book1!mba". Book 1 doesn't exists (wasn't opened, wasn't saved, doesn't have the macros). I've never experienced this problem before?? Can anyone help to solve this problem? FYI The macro to do this is c...

Excel 97 #9
Please can anyone help??? I have two columns in Excel 97. The first contains a list of statu values eg. pending, or granted or withdrawn. The second contains date eg.01/12/1997, 05/06/2003. I woudl like to know how to get all th granted apps before 31/12/2003. Can anyone help please -- Message posted from http://www.ExcelForum.com theres many ways, but an easiest way would be to do a sort. Highlight the 2 columns, click on data, then sort, then sort by status, then by date. this should group them all together. hope this helps...toe >-----Original Message----- >Please can anyo...

How do I Remove a Split from my Comments in Excel 2003? #2
I have set my current workbook to split/freeze the first column and first 2 rows. Now, when I add a comment to the second row (in any column) my comments are cut off if I should scroll down. I don't ever remember the behavior before. And I don't know what I've done to enable it but it's really annoying. How do turn this off ? ...

learning Excel #3
Hi, I was considering learning Excel as an additional tool for my data analysis work. Is it better to use data sets that I have previously used with SPSS and apply the same analysis tools as in SPSS? For applying the appropriate tools, I was considering using excel's online help. The second option I have is to use some excel book for data analysis and apply the techniques to data sets provided with the book. Any suggestions????? regards Metal ...

unable to paste Excel 2003 chart into Outlook 2003
(This was posted on "excel.charting" group.) I have a user who's unable to paste an Excel 2003 chart into Outlook 2003 email message. In Outlook options, the checkbox is selected for "Use Microsoft Office Word 2003 to edit e-mail messages". When I tested this on my own computer running the same version of Office, if the box is check, I have no problem pasting; if this box is cleared, I cannot paste. But on his computer, it doesn't work regardless. Thanks and regards, TL ...

Disable Secure Sockets Layer on exchange server when using RPC over HTTP
Hi im trying to enable RPC over HTTP to enable users to establish contact to my Excahger server 2003 over the internet. Now, I dont want to use SSL (security not that important) and i am told by this article that i can disable SSL in windows registry. Quote: Note While RPC over HTTP does not require Secure Sockets Layer, you must modify the registry to enable RPC over HTTP if you do not want to use Secure Sockets Layer. Microsoft recommends that you enable and require Secure Sockets Layer for your RPC over HTTP communications. At this address: http://support.microsoft.com/?id=833401 But i ...

Having problem with spoofing email
Our users just received multiple email from different users outside the company. In the To: line, it shows his user name correctly but when he print those email, the To: line was showing somebody else name on the print out. Is there a way to block this behavior? I'm using E2k3. For some reason our spam (postini) didn't pick up these emails. Thank you, Could you please post the message in raw format (including the mail headers) Petch wrote: > Our users just received multiple email from different users outside the > company. In the To: line, it shows his user name cor...

outlook 97 and express email problems
Hi, I am currently on an IBM X21 laptop and is running windows 98 se with office 97 pro. I recently experienced some problems with outlook (illegal operations etc) and reinstalled office to fix the problem but since then I have not been able to send or recieve emails with outlook 97 and outlook express 6. I simply get an error message saying the host can't be found (but does exist and I can ping it successfully). Any suggestions on what I might do? I have tried creating new accounts in windows mail and outlook express, but I still get the same error. Thankyou in advance! Tim D...

Outlook 2003 Drag and Drop Emails
I have an issue where there is a SBS 2003 server (newly installed) & when I drag emails to the file system (explorer window) in order to create file records of the emails it generates an error. Dialog Box Name: Error Copying File or Folder Error Msg: Not enough storage is available to process this command. I can't find an error logged anywhere, either on the server event logs or on the local machine event logs... I have searched the MS KB & Office online, but no joy yet... If anyone can help that would be great!!! R ...

using the journal on outlook
Once I link an email to the journal, can I still find that email in my mail box? I seem to be able to get to it only via the journal. If this is the way it is supposed to be, how do I remove it from the journal and get it back into my mail box? Am I just missing something? -- thanks, Independent Are you linking to the item or putting a copy into the journal item? Also, has the item been archived or not? "Independent" <Independent@discussions.microsoft.com> wrote in message news:868279F2-53C8-403A-97F5-604CEECD873C@microsoft.com... > Once I link an email to the journ...

Excel corrupts when asking to update vlookups
We are experiencing weird behavior with some Office 2K3 Excel spreadsheets that contain lots of calculations, but no macros. On some pc’s Excel acts normally, on others you get the error. I have a couple of screen shots available. Any help is appreciated. If desired, send your file to my address below. I will only look if: 1. You send a copy of this message on an inserted sheet 2. You give me the newsgroup and the subject line 3. You send a clear explanation of what you want 4. You send before/after examples and expected results. -- Don Gu...

Emails #3
Hi, I was wondering if anyone knew of any web based email provder that I could use that wont be bloked but the I.T Filer at my work. I require use of emails during the day for personal use but work emails are monitored. I have tired various sites i.e Hotmail, Yahoo, Gmail, lycos etc but they are all blocked. Does anyone know of any that may not be picked up buy the web filer. Fiona Fiona, It is difficult to answer because it depends on what your filter is and how it is monitored. For instance, if it is actively monitored and somebody found out you were accessing the site, then it coul...

Uninstall of mappoint has caused errors with excel
Hi, I am running Office 2003 on the terminal server (windows 2003) and had a copy of mappoint as well. This is a mapping program. We ininstalled mappoint which has caused an error message with Excel and other office products. The error says "Cd:\documents and settings\administrator.ocrdc1\application data\microsoft\addins c:\Program files\common files\microsoft shared\geography\mpoai9.dll is not a valid add-in." I then click OK and excel opens up and everything is fine. The problem is that we are using other programs as well such as Quickbooks that export to excel and t...

Cannot open Outlook, keep getting Send error report of Microsoft.
We are having problems with Outlook 2003. Everytime we try to open, we get this: Send error report to Microsoft. Any ideas why? All windows and office update have been completed. ...

Including and Executing JS and CSS from an ASPX within a Master Pa
I am running into all kinds of difficulties LINKing/Inserting JavaScript and CSS on an ASPX that is inside a MasterPage. I'm not sure what the rules or even what the life-cycle is. Here are the actual issues: 1. Do I have to use code and "RegisterStartupScript()" and all that? Is there no way to do the insertion of these in the actual HTML mark-up of the ASPX page? 2. If I am including jQuery from the MasterPage and *then* want to include a ..JS file from one of the child ASPX pages, I'm running into trouble where it would seem that jQuery has not been insta...

setup Windows Mail as Word 2003 default emailer
All I can do is setup Outlook. I do not use Outlook. I would like to email Word docs using MS Windows Mail (new version of Express) In the Windows Start area, type Regedit into the search bar and then start the Registry Editor and go to HKEY_CURRENT_USER>Software>Clients>Mail Right Click on the (Default) item and then on Modify and in the Value data: field enter Windows Mail so that after you click OK, you have (Default) REG_SZ WIndows Mail -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a pa...