Last active
December 14, 2015 21:28
-
-
Save honda0510/5151042 to your computer and use it in GitHub Desktop.
Gmailの未読メールをフィードとして取得
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
' 参照設定 | |
' Microsoft WinHttp Services, version 5.1 | |
Private Enum HTTPREQUEST_SETCREDENTIALS_FLAGS | |
HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0 | |
HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1 | |
End Enum | |
Private Const URL_GMAIL_FEED As String = "https://mail.google.com/mail/feed/atom/" | |
Private Req As WinHttp.WinHttpRequest | |
Private Sub Class_Initialize() | |
Set Req = New WinHttp.WinHttpRequest | |
End Sub | |
Private Sub Class_Terminate() | |
Set Req = Nothing | |
End Sub | |
Public Function Read(Email As String, Password As String, Optional Label As String = "") | |
Req.Open "GET", URL_GMAIL_FEED & Label, False | |
Req.SetCredentials Email, Password, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER | |
Req.Send | |
If Req.Status <> 200 Then | |
Err.Raise Req.Status, , Req.StatusText | |
End If | |
Read = Req.ResponseText | |
End Function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Sub test() | |
Dim Gmail As Gmail | |
Dim Email As String | |
Dim Password As String | |
Dim Label As String | |
Dim Feed As String | |
Email = Range("A1").Value | |
Password = Range("A2").Value | |
Label = "unread" | |
Set Gmail = New Gmail | |
Feed = Gmail.Read(Email, Password, Label) | |
Debug.Print Feed | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment