How to retrieve the number of E-mail messages from mail server using VB.net and IMAP? - vb.net

I managed to get a successful reply from the mail server (Gmail.com) using IMAP and vb.net with this code in this post
Now, I want to retrieve the number of E-mail messages from Inbox folder, how to do it?!

After you connect to the server, you'll issue a set of commands like this:
A001 LOGIN <username> <password>
A002 SELECT INBOX
In response to the SELECT INBOX, the server will respond with a bunch of responses:
* OK [UIDVALIDITY 38]
* 13 EXISTS
* 0 RECENT
A002 OK Inbox selected.
...
The EXISTS response is the number of messages in the INBOX.

Related

Parse logs with SQL query to collect data in Log Parser Studio

Excuse me for the question, my SQL knowledge is extremely limited. I'm trying to find anonymous connections in the exchange logs (I'm using Log Parser Studio which analyzes logs in bulk and parses them with SQL query). In the logs I see this:
#Fields: date-time,connector-id,session-id,sequence-number,local-endpoint,remote-endpoint,event,data,context
2020-01-10T01:01:01.111X,Inbound Proxy Internal Send Connector,01C1Z111DD1X11Z1,212,192.168.1.1:21111,192.168.1.2:5565,*,,Proxying inbound session with session id 01C1Z111DD1X11Z1
2020-01-10T01:01:01.111X,Inbound Proxy Internal Send Connector,01C1Z111DD1X11Z1,213,192.168.1.1:21111,192.168.1.2:5565,>,RSET,
2020-01-10T01:01:01.112X,Inbound Proxy Internal Send Connector,01C1Z111DD1X11Z1,214,192.168.1.1:21111,192.168.1.2:5565,<,250 2.0.0 Resetting,
2020-01-10T01:01:01.112X,Inbound Proxy Internal Send Connector,01C1Z111DD1X11Z1,215,192.168.1.1:21111,192.168.1.2:5565,>,XPROXYFROM SID=08D7F721DC0D9A14 IP=215,192.168.1.1 PORT=21111 DOMAIN=CONTOSO.COM SEQNUM=1 PERMS=1077 AUTHsrc=Anonymous,
2020-01-10T01:01:01.113X,Inbound Proxy Internal Send Connector,01C1Z111DD1X11Z1,216,192.168.1.1:21111,192.168.1.2:5565,<,250 XProxyFrom accepted,
2020-01-10T01:01:01.113X,Inbound Proxy Internal Send Connector,01C1Z111DD1X11Z1,217,192.168.1.1:21111,192.168.1.2:5565,*,,sending message with RecordId 151516 and InternetMessageId <j6hd87fh-55h6-66h6-5g55-k9dj47gk704z#VM1203102312.contoso.com>
2020-01-10T01:01:01.113X,Inbound Proxy Internal Send Connector,01C1Z111DD1X11Z1,218,192.168.1.1:21111,192.168.1.2:5565,>,MAIL FROM:<test#contoso.com> SIZE=0 AUTH=<> XMESSAGEVALUE=MediumHigh,
2020-01-10T01:01:01.113X,Inbound Proxy Internal Send Connector,01C1Z111DD1X11Z1,219,192.168.1.1:21111,192.168.1.2:5565,>,RCPT TO:<receive#contoso.com>,
2020-01-10T01:01:01.115X,Inbound Proxy Internal Send Connector,01C1Z111DD1X11Z1,210,192.168.1.1:21111,192.168.1.2:5565,<,250 2.1.0 Sender OK,
2020-01-10T01:01:01.115X,Inbound Proxy Internal Send Connector,01C1Z111DD1X11Z1,211,192.168.1.1:21111,192.168.1.2:5565,<,250 2.1.5 Recipient OK,
So, I need to find data with "AUTHsrc=Anonymous" and then only show "IP", "MAIL FROM" and "RCPT TO" records from the session-id where "AUTHsrc=Anonymous" exists.
I managed to create a query to list only those IDs I'm after:
SELECT * FROM '[LOGFILEPATH]'
WHERE data LIKE '%AUTHsrc=Anonymous%'
But I don't know how to display other records based on my finding. I would assume I need a subquery?
picture for the reference
Maybe I didn't understand your wording, but the query below finds all unique session-ids with AUTHsrc=Anonymous
SELECT DISTINCT session_id FROM '[LOGFILEPATH]'
WHERE data LIKE '%AUTHsrc=Anonymous%'
And so this query will select all records with any of these session-ids
SELECT * FROM '[LOGFILEPATH]'
WHERE session_id IN (
SELECT DISTINCT session_id FROM '[LOGFILEPATH]'
WHERE data LIKE '%AUTHsrc=Anonymous%'
)
Put some particular columns instead of * to reduce the output to IP and all other data you're interested in.

"Mailbox size limit exceeded" when sending mails on an empty exchange account with MailKit .Net

I am using MimeKit and Mailkit to send emails from my VB.NET application, through my own SMTP server (run on Windows Server 2016, with SmarterMail).
Until then, I was sending emails to info#mywebsite.com which is an alias of infos#mywebsite.com and it worked very well. This email account is a exchange account with more of 49 Gio free.
Since a few days, I've received this error : Mailbox size limit exceeded
When a set a spy on it, this is what I get :
This is the log :
S: 235 Authentication successful
C: MAIL FROM:<info1#mywebsite.com> SIZE=599
S: 250 OK <info1#mywebsite.com> Sender ok
C: RCPT TO:<info#mywebsite.com>
S: 452 <info#mywebsite.com> Mailbox size limit exceeded
C: RSET
S: 250 OK
I don't understand why I get this error while my recipient account is pretty much empty.
When I try to send email from my outlook account to info#mywebsite, I get no error.
When I try to send emails from my code to anothers recipients, I get no error.
My disk space is very large on my mail serveur (almost 2 To).
This is my code :
Dim message As New MimeMessage()
message.From.Add(New MailboxAddress("My website", "info1#mywebsite.com"))
message.To.Add(New MailboxAddress("My website", "info#mywebsite.com"))
message.Subject = "any subject"
Dim builder As New BodyBuilder()
builder.TextBody = textemail
builder.HtmlBody = htmlemail
message.Body = builder.ToMessageBody()
' SERVER SMTP
Using client As New MailKit.Net.Smtp.SmtpClient()
client.ServerCertificateValidationCallback = (Function(sender, certificate, chain, sslPolicyErrors) True)
client.Connect("mail.mysmtpserver.com", 587, MailKit.Security.SecureSocketOptions.None)
client.Authenticate("Mailkit_SMTP_UserName", "Mailkit_SMTP_Password")
client.Send(message)
client.Disconnect(True)
End Using
Thanks a lot for any suggestion (I don't find any related topic on Google)
I've found what was wrong in my SMTP server : Smartermail has it own mailbox size configuration for any mail account, that is limited at 100Mb.
You can change it by going on : your domain > Manage > Account

Database Mail not sending

I'm trying to send email using the DatabaseMail on SQL Server 2008; I can see my emails sitting in the msdb.dbo.sysmail_unsentitems
But they just sit there and I get no error messages.
I've checked and I have rights to use the DatabaseMail by using the following:
EXEC msdb.sys.sp_helprolemember 'DatabaseMailUserRole';
And I tried running
EXEC msdb.dbo.sysmail_help_queue_sp #queue_type = 'mail';
which shows the length as the number of emails I've tried to send, but the Status is showing as Inactive.
Am I missing something else?

How to sync for the emails which are received after a particular email.

I am working on an application which download Yahoo account emails in the order of down to top using Yahoo Mail API's.
Application sync logic works like below
Lets say Inbox consists of 1000 emails.
1) Initially fetching 100 emails message ID's by using "ListMessages" with parameters startMid = 0 and numMid=100.
2) Processing chunk emails .
3) Now requesting for the next chunk emails by giving the startMid = 100 and numMid=100.
The above logic works fine if user is not deleting any emails during syncing.
Is there any way to retrieve next chunk emails based on the message ID (string unique value) rather than message number.
What is the logic for syncing the emails from the last processed message?
PS:I can not rely on message number (since message number is not meant for unique identifier of a message).
I was looking for the same thing and found "How to get only emails which are arrived from the Client last sync." (http://developer.yahoo.com/forum/Yahoo-Mail-Web-Services-API/How-to-get-only-emails-which/1320329478746-16f18e6a-aadd-40c3-b259-e095ce80a1e6) where some guy reply "This feature is not available right now but we do plan to support this in future." date: 3 Nov 2011 11:24 AM
I think you can query mailTables (with YQL) or ListMessage (Api) and get the complete list of messages id (without any info) eg: SELECT * FROM ymail.messages WHERE numInfo="0"
And then "count" the position of the last message you got and then, get mail from that number. Eg: SELECT * FROM ymail.messages WHERE startMid="3" and numMid="100"
What do you think?
Greetings from Argentina
PS: sorry about my horrible english

sql db mail problem while sending in bulk

I am using db mail(sql server 2005) to send bulk email(>2000).
The code tat i use is,
exec msdb..sp_send_dbmail
#profile_name = 'My Profile',
#recipients = 'raghav.cinch#gmail.com',
#subject = 'test',
#body = 'test',
#body_format = 'HTML'
If i send few emails(less than 100), all emails are sent successfully. But only bulk emails give me error.
The error I get is,
The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 8 (2011-09-27T21:29:17). Exception Message: Cannot send mails to mail server. (Unable to send to all recipients.).
)
The error comes after 100 or 105 mails. The email addresses are correct and if i sent in cycles of 100, all mails are sent successfully.
I believe it should be some configuration settings tat need to be tweaked. Could someone pls help me in fixing it..
Thanks in advance.
Changed the iis6 settings, max queue length for the smtp server and this worked like charm.