Check for new mails in Hotmail using OpenPop.NET - c#

I was advised to use OpenPop lib to fetch my mail from hotmail. But I could'nt find any better way to check for new mail except disconnecting and reconnecting again. And there, I found a problem, Hotmail doesn't allow more than 1 pop3 login each 15 minutes. I want to know if it's possible to get the new mail without disconnecting and reconnecting to their pop3 server. Here is my code:
Timer checker = new Timer();
checker.Interval = 1000;
checker.Tick += new EventHandler(delegate
{
Pop3Client client = new Pop3Client();
client.Connect("pop3.live.com", 995, true);
client.Authenticate("my.Email#hotmail.com", "myPassword");
label1.Text = client.GetMessageCount().ToString();
client.Disconnect();
});
checker.Start();

I do not think that servers are allowed to show new mails to you during a POP3 session. I base this upon that it can certainly not delete emails as it would destroy the message numbers.
What would for example happen if the server says you have 100 messages, and when you fetch the message with number 55, it is actually not there since it was deleted in the meantime. I think the same applies to adding new emails during the session. Also, only one client can be logged into a POP3 account at a time, since the account will then be in a locked state. In that locked state, I do not think servers are allowed to change anything during the session.
I do not recall any methods in the POP3 specification which allows you to ask the server if new messages have been delivered.
If Hotmail does indeed only allow one POP3 login per 15 minutes, then I think you are left with just that. I do not know if there are other protocols which could be used here. IMAP is not supported, so that is not an option.
This is not the answer you want - but it is what I can give you.

Doesn't hotmail use DeltaSync also, for the SOAP API ?
You can use oSpy to see what gets sent and received over SSL, and replicate that functionality.

Related

Unable to send mail from C# App using godaddy details

Despite spending an entire morning with GoDaddy chat, and reading almost everything I can find on sending emails via godaddy I am still no closer to solving my issue.
What Have I tried
Firstly, this is my code.
var smtpClient = new SmtpClient("smtpout.secureserver.net")
// var smtpClient = new SmtpClient("relay-hosting.secureserver.net", 25)
{
Port = 25,
UseDefaultCredentials = false,
EnableSsl = false,
Credentials = new NetworkCredential("user#User.com", "Password#"),
// DeliveryMethod = SmtpDeliveryMethod.Network,
};
and I think I should mention that this works when I attempt to use google's free smpt server, the mail is sent. However using my godaddy credentials, I get the following error,
Message = "Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 72.167.234.197 (72.167.234.197:25), connect error 10060" other times it says
InnerException = {"Unable to read data from the transport connection: An established connection was aborted by the software in your host machine."}
I have also tried other suggested ports like 587 , 80, 3552. Nothing has changed, I have also tried the suggestion at this link https://www.godaddy.com/help/send-email-using-systemnetmail-19291 . Which did not work (no suprise to me, cause where am i putting the account password) . Would appreciate it if anyone has solved getting their C# application to work with Godaddy. Like I said it works with Google so I dont believe my code is an issue in anyway.
regards
Your code looks good, however, one way to test if you are using the correct smtp settings is to send the email with a program like Microsoft Outlook or Thunderbird. Also, if you are using a dedicated server or a VPS, you need to use
dedrelay.secureserver.net
See: https://in.godaddy.com/help/what-is-my-servers-email-relay-server-16601
Also, check out this see: https://in.godaddy.com/community/VPS-Dedicated-Servers/Unable-to-send-email-from-C-net-application-from-website/m-p/102913#M1256
which mentions: "If you are using a Plesk shared hosting plan, use relay-hosting.secureserver.net and port 25. Do not specify a username or password. Other relay/smtp servers will not work from our shared hosting."

MailKit and mulitple clients on same mail account

Is there any limits on how many concurrent clients you can connect to one mail account?
I have an app that opens a new ImapClient on each request. The ImapClient will open INBOX and FolderA, and move a mail by UID from one to another. The multiple clients will never access the same mail concurrent, but probably move multiple mails in same account concurrent.
Errors seems to occur once I hit about 5+ clients simultanious, using Exchange, and response with a lot of different errors as:
"The IMAP server replied to the 'COPY' command with a 'NO' response."
"The IMAP server replied to the 'EXPUNGE' command with a 'NO' response."
When I'm moving mails I do following sequence:
Using a new ImapClient
Connect and auth the client
GetFolderAsync of INBOX and FolderA, then wait for the response
Open the INBOX with OpenSync() with ReadWrite, and wait for the task.
Fetch INBOX with FetchAsync(), looping through the result to find the wanted UID based on MessageID
Calling MoveToAsync() moving the mail based on uid to the FolderA, and waiting
FolderA.SetFlagAsync() with new UID, and flagging the mail with SEEN
Waiting on 6. & 7.
INBOX.SetFlagAsync() with the previous UID, and flagging the mail with DELETED, wait for the operation
Closing IMAP folders using INBOX.CloseAsync and FolderA.CloseAsync
There is no standard that defines the maximum number of clients an IMAP server will allow. I've read that Thunderbird uses a max of 5 concurrent connections (which probably suggests they found that worked well for most IMAP servers in the wild), so that might explain what you are seeing.

Send bulk Mail Notifications

I want to send above 500 to 2500 mails at a time using SMTP currently it is working for me but it is taking too much for all mails have to delivered so please suggest me the best method to send bulk mails with very less possible time, I used the below code.
string readMail = null;
System.Net.Mail.SmtpClient smtpClient = null;
smtpClient = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtpClient.UseDefaultCredentials = false;
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 587;
smtpClient.Credentials = new NetworkCredential("myemail#example.net", "password");
smtpClient.EnableSsl = true;
smtpClient.SendCompleted += new SendCompletedEventHandler(cleint_Responce);
object userState = m;
try
{
smtpClient.SendAsync(m,userState);
}
Gmail isn’t designed for sending bulk email. If you are planning to send an email message to a large group of friends using Gmail, do read the following rules to avoid temporary lockdown of your Gmail:
Rule 1: You can send emails to a maximum of 500 recipients per day through the Gmail website. Try exceeding the limit and your Gmail account may get temporarily disabled with the error – “Gmail Lockdown in Section 4.”
It is important to note that this limit is around recipients and not messages. Thus you can send 10 emails to 50 people each or 1 email can be addressed to a maximum of 500 people.
Rule 2: If you access Gmail via POP or IMAP clients, like Microsoft Outlook or Apple Mail, you can send an email message to a maximum of 100 people at a time. If you exceed the limit, your account may be disabled for a day with the error – “550 5.4.5 Daily sending quota exceeded.”
Rule 3: Always double check email addresses of recipients before hitting the Send button in Gmail. That’s because your account may get disabled if the email message contains a large number of non-existent or broken addresses (<25 ?) that bounce back on failed delivery.
Rule 4: You can associate multiple email addresses with your Gmail account and send emails on behalf of any other address. However, when sending mail from a different address, the original account’s message limits are applied.
Rule 5: If you are sending emails through Google Script, like in the case of Gmail Mail Merge, the daily sending limit is 100 recipients per day for free Gmail accounts. You can use the MailApp.GetRemainingDailyQuota method to know your existing quota else the script will throw an exception saying – “Service invoked too many times.”
If you wish to send more email messages through Google Scripts, you’ll have to upgrade to Google Apps. Even then, your sending limits will be only be increased after a few billing cycles or if you have opted for 5 or more users.
There are some paid service will help you better on this like Sendblaster

Bulk mailing using SMTP server in ASP.Net

We are sending free newsletters to all users who have registered for this service. Since these newsletters are sent free of cost we expect at least 5000 subscribers within a month. I am worried whether bulk mailing using SMTP server concept will cause some issue. First we thought of developing a windows service which would automatically mail to subscribers on periodical basis but the business users have given requirement that the newsletters should be editable by the admin and then only mailed to users so we had to develop this functionality in website itself!. I get the subscribers for the particular user in data table and then mail to each user inside for loop, will this cause any performance issue?
The code is pasted below:
dsEmailds.Tables[0] has list of newsletter subscribers.
for (iCnt = 0; iCnt < dsEmailIds.Tables[0].Rows.Count; iCnt++)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("newsletters#domainname.com", "test1");
msg.To.Add(dsEmailIds.Tables[0].Rows[iCnt]["mailid"]);
msg.IsBodyHtml = true;
msg.Subject = subject;
AlternateView av1 = AlternateView.CreateAlternateViewFromString(MailMsg, null, System.Net.Mime.MediaTypeNames.Text.Html);
av1.LinkedResources.Add(lnkResLogo);
av1.LinkedResources.Add(lnkResSalesProperty);
av1.LinkedResources.Add(lnkResLeaseProperty);
msg.AlternateViews.Add(av1);
SmtpClient objSMTPClient = new SmtpClient(System.Configuration.ConfigurationManager.AppSettings["mailserver"].ToString());
objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSMTPClient.Send(msg);
}
Any suggestions would be great!
You should STOP and consider all sort of things:
Black List: with that amount you will for sure be balck listed in severeal ISP's / Mail Servers, and you need to prove that the received user asked for such email and wait 1 to 3 month process while they remove the flag
You need to send emails in blocks, not more than 250 at each time, use different IP's machines to send more emails (more blocks)
please read some nice guidelines for doing all this, you can find it in MailChimp and Campaign Monitor
Free Email Marketing Guides
You should use a service, like Mailchimp (now it's free to 1000 subscribes, 3000 sends a month) but prices are very cheap and they have an API that you can easily add, create, send and you will get all those nice reports on how opened, what did they do, etc ...
Campaign Monitor is fantastic as well, but a little bit more expensive but great as you can brand the entire UI and sell as a service to your customers (if you are thinking of doing such thing in the near future).
I hope it helps.
give them a try, I'm a happy customer.
The main problem i see is that you may encounter a page timeout. The best way to do it in my opinion would be to set up a service that will take care of mail-related uses (templating for example) by reading from a queue. Your website could just post the mails you expect to send in the queue, then offer a basic administration panel to manage the service and get some stats.
You can use open-source & xcopy-friendly systems for the queue like Rhino queue, or ServiceBus, and Topshelf for services if you want easy setup
But i'd recommend you not to send bulk emails in the webpage
There is a SendAsync method that will actually queue up these requests and send them async from your thread. This way you can prevent the timeout and you can probably send (ie. queue) 5000 emails within seconds.
Write to a pickup queue of an SMTP server running on the machine (IIS includes one). This is the fastest and most efficient method.
OR
Setup a custom thread pool in your code and offload the task to it. That way worker threads from ASP.NET thread pool are ready to serve incoming requests and won't be occupied with sending mails (that depends on how high your server load is, of course - go ahead with ASP.NET thread pool using async methods if you don't care about the load/can afford it).

Is there a way to perpetuate the email session in a C# application?

Using this code, I can send emails to people. However, every time I press the send button, I think I log back in, correct?
Is there a way to perpetuate my login session, or is the way it's always been done ("I'm making a newbie assumption")?
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("papuccino1#gmail.com", "password"),
EnableSsl = true
};
client.Send("papuccino1#gmail.com", "stapia.gutierrez#gmail.com", "test", "testbody");
Console.WriteLine("Sent");
Console.ReadLine();
The code you have is fine. Yes, the smtp service is sending the credentials to the smtp server each time you send the email.
From a coding perspective, this is the preferred way of doing things. If you are batching emails, then you would simply put the .Send method call inside the loop while the new SmtpClient call is above it.
You only want to leave the connection open long enough to do the job then you close it. Otherwise you run the risk of the app blowing up or otherwise failing to close the connection later. Servers only have a limited number of connections that they can handle. If most apps left them open for long periods of time then other users would have a hard time getting in.
Most mail clients, open the connection, send any emails in the outbox, grab any new emails, then close the connection. When a timer goes off, it will do the process over again.
Outlook tied to Exchange works slightly differently because there is a push component (from the server).
Each SMTP session starts with authentication usually. As far as I know there is no way to keep a session open to a SMTP server. It is possble to send a number of emails in a batch though, this is probably what happens when you use an email client.

Categories