PDA

View Full Version : Attachment to gmail



hunna
02-27-2013, 10:38 AM
Hello all, I am now trying to add the attachment to gmail (CDO and through Outlook express not working for me) using

IEX.Navigate https://mail.google.com/mail/?view=cm&fs=1&to=h@gmail.com&su=Result&body=text1%0atext2&bcc=h@gmail.com&cc=h@gmail.com&attachment=C:\tt.txt"
The code can input recipient emails (To, CC, Bcc), subject and body. Could anyone please check why this code doesn't send the attachment to my gmail?

Any help would be appreciated!!! :yes:bow:

mohanvijay
02-28-2013, 12:02 AM
try this

http://www.vbaexpress.com/kb/getarticle.php?kb_id=1146

hunna
02-28-2013, 06:59 AM
@mohanvijay (http://www.vbaexpress.com/forum/member.php?u=36127) thank you for a nice link.

Could you help me a bit more. I was wondering how to trigger the "send" button.

I have tried

OB_Doc.all("nvp_bu_send").Click

but it's not working.

Thank you in advance!!!

Kenneth Hobs
02-28-2013, 07:37 AM
In this CDO example, it does not show the from email address but the login address so if you expect to send it by an anonymous email address, this would not work for you.

Sub Test_Gmail()
Gmail "kenneth.hobson@gmail.com", "ken", "Hello World!", _
"This is a test using CDO to send Gmail with an attachement.", _
"ken@odot.org", "anonymous@somewhere.com", _
"x:\test\test.xlsm"
End Sub

' http://www.blueclaw-db.com/access_email_gmail.htm
' http://msdn.microsoft.com/en-us/library/ms872547%28EXCHG.65%29.aspx
' Add CDO reference for early binding method
' Tools > References > Microsoft CDO for Windows 2000 Library
' c:\windows\system32\cdosys.dll
' http://www.rondebruin.nl/cdo.htm 'Other cdo tips for cdo to Outlook from Excel
Function Gmail(sendUsername As String, sendPassword As String, subject As String, _
textBody As String, sendTo As String, sendFrom As String, _
Optional sAttachment As String = "")

'Dim cdomsg as Object
' Set cdomsg = CreateObject("CDO.message") 'late binding method
Dim cdomsg As New CDO.Message 'early binding method
With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 587
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = sendUsername
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = sendPassword
.Update
End With
' build email parts
With cdomsg
.To = sendTo
.From = sendFrom
.subject = subject
.textBody = textBody
If Dir(sAttachment) = "" Then sAttachment = ""
If sAttachment <> "" Then .AddAttachment (sAttachment)
.Send
End With
Set cdomsg = Nothing
End Function