By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

CDO Message with gmail doesn't send attachment

P: 2
I am trying to send an attachment using CDO message on a gmail account.

The email is sent, but it does not have the attachment.

Here is my code:
---------------------
Expand|Select|Wrap|Line Numbers
  1. Function fcnSendPage(strTo As String, AMS As String)
  2. 'Dim cdoMessage
  3.  
  4.     Set cdoMessage = CreateObject("CDO.Message")
  5.  
  6.     With cdoMessage.Configuration.Fields
  7.         .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send using the network (SMTP over the newtork)
  8.         .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
  9.         .Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 587
  10.         .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
  11.         .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
  12.         .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
  13.         .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "myusername@gmail.com"
  14.         .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
  15.         .Update
  16.     End With
  17.  
  18.     With cdoMessage
  19.         .To = strTo
  20.         .From = "myusername@gmail.com"
  21.         .TextBody = "Debrief on flight " & AMS & " has been completed."
  22.         .Send
  23.         .AddAttachment "C:\Databases\Debrief_0808-00119.rtf"
  24.         'MsgBox strTo & ": Debrief on flight " & AMS & " has been completed."
  25.     End With
  26.  
  27.     Set cdoConfig = Nothing
  28.     Set cdoMessage = Nothing
  29.  
  30. End Function
------------------------
Any thoughts?
Oct 20 '08 #1
Share this Question
Share on Google+
5 Replies


GazMathias
Expert 100+
P: 189
Expand|Select|Wrap|Line Numbers
  1. .Send
  2. .AddAttachment "C:\Databases\Debrief_0808-00119.rtf"
  3.  
Would you not add the attachment before the .Send command?

Expand|Select|Wrap|Line Numbers
  1. .AddAttachment "C:\Databases\Debrief_0808-00119.rtf"
  2. .Send
  3.  
Just a thought.
Oct 21 '08 #2

P: 2
Wow...Feeling pretty stupid about right now.

Worked perfectly.

Thanks for pointing out what is now very obvious :)
Oct 21 '08 #3

GazMathias
Expert 100+
P: 189
No problem,

Sometimes a fresh pair of eyes helps heaps, even for the blindingly obvious.
Oct 21 '08 #4

P: 1
How to receive mails using CDO Message in VB.Net.
Jul 12 '09 #5

P: 1
Hi there!
I'm using vufltrn's code. I typed it as it is, but I'm getting an error while sending the email:
"Error de transporte en la conexion al servidor"

It's in spanish, it seems that there's some transport error with the connection to gmail's server.
Any ideas?
Jul 12 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.