Last active
July 19, 2020 07:03
-
-
Save tienuit/d21c3eb7984c368b7a422895451837b0 to your computer and use it in GitHub Desktop.
Get Momo Received Transaction via Email
This file contains hidden or 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
//MailKit https://www.nuget.org/packages/MailKit | |
//Note: Must Turn on "Less secure app access" on your Google account | |
using MailKit; | |
using MailKit.Net.Imap; | |
using MailKit.Search; | |
using System; | |
using System.Text.RegularExpressions; | |
using System.Threading; | |
namespace GetMomo | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
using (var client = new ImapClient()) | |
{ | |
using (var cancel = new CancellationTokenSource()) | |
{ | |
client.Connect("imap.gmail.com", 993, true); | |
client.AuthenticationMechanisms.Remove("XOAUTH2"); | |
client.Authenticate("youremail", "password"); | |
var inbox = client.Inbox; | |
inbox.Open(FolderAccess.ReadOnly, cancel.Token); | |
var query = SearchQuery.DeliveredAfter(DateTime.Parse("2020-01-01")) | |
.And(SearchQuery.SubjectContains("nhận được tiền")) | |
.And(SearchQuery.FromContains("@momo.vn")); | |
foreach (var uid in inbox.Search(query, cancel.Token)) | |
{ | |
var mail = inbox.GetMessage(uid, cancel.Token); | |
Regex regex = new Regex("style=\"color:#3C4043;margin:0px;font-size:12px;line-height:22px; font-weight: normal; font-size: 15px;\">\r\n(.+)<\\/div>"); | |
var matches = regex.Matches(mail.HtmlBody); | |
if(matches.Count == 6) | |
{ | |
var money = matches[0].Groups[1].Value.Trim(); | |
var name = matches[1].Groups[1].Value.Trim(); | |
var phone = matches[2].Groups[1].Value.Trim(); | |
var datetime = matches[3].Groups[1].Value.Trim(); | |
var message = matches[4].Groups[1].Value.Trim(); | |
var transactionId = matches[5].Groups[1].Value.Trim(); | |
Console.WriteLine("Money: {0}, Name = {1}, Phone = {2}, Date Time = {3}, Massage = {4}, Transaction Id = {5}", money, name, phone, datetime, message, transactionId); | |
} | |
} | |
Console.ReadKey(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment