ExcelTheCell
Board Regular
- Joined
- Nov 14, 2010
- Messages
- 158
Code:
IE.Navigate "[URL]https://mail.google.com/mail/u/0/#inbox[/URL]"
Any easy way...
Last edited:
IE.Navigate "[URL]https://mail.google.com/mail/u/0/#inbox[/URL]"
Private Sub GenerateMailGail()
'Definine constants
Const NavigationUrl = "http://mail.google.com"
Const Username = "mrexceltest@gmail.com"
Const Password = "mrexceltest321"
'Define dimensions
Dim IEX As InternetExplorer
Dim IEXDoc As HTMLDocument '---------->Returns an HTMLDocument object that specifies _
the HTML object model associated with the HTML _
document in the current view (assuming one exists).
Dim IEXLF As HTMLFormElement
Dim UserNameInputBox As HTMLInputElement
Dim PasswordInputBox As HTMLInputElement
Dim SignInButton As HTMLInputButtonElement
'Action to navigate to the specific site
Set IEX = New InternetExplorer
IEX.Visible = True
IEX.Navigate NavigationUrl
Do While IEX.ReadyState <> 4 Or IEX.Busy: DoEvents: Loop
Set IEXDoc = IEX.Document 'you get [object]
On Error GoTo NextStep
'Data found in sorce code of the HTML page
'<form id="gaia_loginform" action="https://accounts.google.com/ServiceLoginAuth" method="post">
Set IEXLF = IEXDoc.forms("gaia_loginform")
'Data found in source code of the HTML page
'<div class="email-div">
'<label for="Email"><strong class="email-label">Username</strong></label>
'<input type="text" spellcheck="false" _
name="Email" id="Email" value="">
'</div>
Set UserNameInputBox = IEXLF.elements("Email")
UserNameInputBox.Value = Username
'Data found in source code of the HTML page
'<div class="passwd-div">
'<label for="Passwd"><strong class="passwd-label">Password</strong></label>
'<input type="password" name="Passwd" id="Passwd">
'</div>
Set PasswordInputBox = IEXLF.elements("Passwd")
PasswordInputBox.Value = Password
'Data found in source code of the HTML page
'<input type="submit" class="g-button g-button-submit" name="signIn" id="signIn" value="Submit">
Set SignInButton = IEXLF.elements("signIn")
SignInButton.Click
NextStep:
Const NavigationCompose = "https://mail.google.com/mail/u/0/#compose"
Dim EmailForm As HTMLFormElement
Dim TableSelection As HTMLTable
IEX.Navigate "https://mail.google.com/mail/u/0/#compose"
Do While IEX.ReadyState <> 4 Or IEX.Busy: DoEvents: Loop
Application.Wait Now + TimeValue("00:00:05")
IEX.Quit
End Sub
Function AddIEFRAME()
'Add referance from library named Microsoft internet contol
On Error GoTo 1
ThisWorkbook.VBProject.References.AddFromFile ("C:\WINDOWS\System32\ieframe.dll")
1:
End Function
Function AddMsHtml()
'Add referance from library named Microsoft HTML object library
On Error GoTo 1
ThisWorkbook.VBProject.References.AddFromFile ("C:\WINDOWS\System32\MsHtml.tlb")
1:
End Function
Function AddCDOWIN()
'Add referance from library named Microsoft CDO for WIn 2000 library
On Error GoTo 1
ThisWorkbook.VBProject.References.AddFromFile ("C:\WINDOWS\System32\cdosys.dll")
1:
End Function
Function AddIEFRAME()
'Add referance from library named Microsoft internet contol
On Error GoTo 1
ThisWorkbook.VBProject.References.AddFromFile ("C:\WINDOWS\System32\ieframe.dll")
1:
End Function
Function AddMsHtml()
'Add referance from library named Microsoft HTML object library
On Error GoTo 1
ThisWorkbook.VBProject.References.AddFromFile ("C:\WINDOWS\System32\MsHtml.tlb")
1:
End Function
Function AddCDOWIN()
'Add referance from library named Microsoft CDO for WIn 2000 library
On Error GoTo 1
ThisWorkbook.VBProject.References.AddFromFile ("C:\WINDOWS\System32\cdosys.dll")
1:
End Function
Sub CDO_Mail_Small_Text_2()
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
Dim Flds As Variant
Call AddIEFRAME
Call AddMsHtml
Call AddCDOWIN
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("[URL]http://schemas.microsoft.com/cdo/con...ion/smtpusessl[/URL]") = True
.Item("[URL]http://schemas.microsoft.com/cdo/con...tpauthenticate[/URL]") = 1
.Item("[URL]http://schemas.microsoft.com/cdo/con...n/sendusername[/URL]") = "dudde"
.Item("[URL]http://schemas.microsoft.com/cdo/con...n/sendpassword[/URL]") = "My pass goes here and it does not work"
.Item("[URL]http://schemas.microsoft.com/cdo/con...ion/sendserver[/URL]") = "smtp.gmail.com"
.Item("[URL]http://schemas.microsoft.com/cdo/con...tion/sendusing[/URL]") = 2
.Item("[URL]http://schemas.microsoft.com/cdo/con...smtpserverport[/URL]") = 25 (I've tried 465)
.Update
End With
strbody = "Hi there" & 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 = "Mail address receiver"
.CC = "dude"
.BCC = ""
.ReplyTo = "[EMAIL="dude@rangel.pt"]dude@rangel.pt[/EMAIL]"
.From = """Antonio"" "
.Subject = "Important message"
.TextBody = strbody
.Send (here is where the debug error thing comes in)
End With
End Sub
Private Sub GenerateMailGail()
'Definine constants
Const NavigationUrl = "[URL]http://mail.google.com[/URL]"
Const Username = "[EMAIL="mrexceltest@gmail.com"]mrexceltest@gmail.com[/EMAIL]"
Const Password = "mrexceltest321"
'Define dimensions
Dim IEX As InternetExplorer
Dim IEXDoc As HTMLDocument '---------->Returns an HTMLDocument object that specifies _
the HTML object model associated with the HTML _
document in the current view (assuming one exists).
Dim IEXLF As HTMLFormElement
Dim UserNameInputBox As HTMLInputElement
Dim PasswordInputBox As HTMLInputElement
Dim SignInButton As HTMLInputButtonElement
'Action to navigate to the specific site
Set IEX = New InternetExplorer
IEX.Visible = True
IEX.Navigate NavigationUrl
Do While IEX.ReadyState <> 4 Or IEX.Busy: DoEvents: Loop
Set IEXDoc = IEX.Document 'you get [object]
On Error GoTo NextStep
'Data found in sorce code of the HTML page
'<FORM id=gaia_loginform action="<a href=" target=_blank ServiceLoginAuth? accounts.google.com https:>https://accounts.google.com/ServiceLoginAuth</A>" method="post">
Set IEXLF = IEXDoc.forms("gaia_loginform")
'Data found in source code of the HTML page
'
'<LABEL for=Email>[B]Username[/B]</LABEL>
'<INPUT spellcheck="false" _
name="Email" id="Email" value="">
'
Set UserNameInputBox = IEXLF.elements("Email")
UserNameInputBox.Value = Username
'Data found in source code of the HTML page
'
'<LABEL for=Passwd>[B]Password[/B]</LABEL>
'<INPUT id=Passwd name=Passwd type="password">
'
Set PasswordInputBox = IEXLF.elements("Passwd")
PasswordInputBox.Value = Password
'Data found in source code of the HTML page
<INPUT id=signIn class="g-button g-button-submit" value=Submit type=submit name=signIn>
Set SignInButton = IEXLF.elements("signIn")
SignInButton.Click
NextStep:
Const NavigationCompose = "[URL]https://mail.google.com/mail/u/0/#compose[/URL]"
Dim EmailForm As HTMLFormElement
Dim TableSelection As HTMLTable
IEX.Navigate "[URL]https://mail.google.com/mail/u/0/#compose[/URL]"
Do While IEX.ReadyState <> 4 Or IEX.Busy: DoEvents: Loop
Application.Wait Now + TimeValue("00:00:05")
IEX.Quit
Exit Sub