Send bulk Mail Notifications - c#

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

Related

creating smtp server and read the emails c#

I am given a task to create a new smtp mail server which can receive mail using C#.
While going through the articles i read we can send emails via SMTP but we have to receive or read using POP.
I was directed to links by some stackoverflow already existing questions:
Rnwood and sourceforge
Rnwood I am sorry but i did not understand how to use it.
source forge the msi asked to download if we run it, it asks to download framework 1.1.4322 which will not install in my system and throw error.
Usually there are codes for sending messages so I tried msdn example
I used localhost as the server and 587 as the port.
which gives me error (for any port 587,25)
I also found an article here which actually monitors the localhost and specified port when I try to run the msdn code.
But still I am unable to send email to test in any way.
So is there any way I can code to set up smtp in my own server and receive email and test.
Setting up and configuring a mail server is a completely different ball game than just sending or reading emails from an existing IMAP / POP3 server.
A mail server consists of a number of components such as:
A Mail Transfer Agent (MTA) that handles SMTP traffic and which is responsible for sending email from your users to an external MTA and to receive email from an external MTA.
Mail Delivery Agent which retrieves mail from the MTA and places it in the recipient's mailbox.
A domain name with appropriate DNS records and an SSL certificate.
A server that provides IMAP / POP3 functionality.
In short... stick to publicly available mail servers...
In your post you referenced the SmtpClient from the .NET framework. That library is used to connect to an existing mail server. You can use it like this.
MailMessage message = new MailMessage();
message.From = new MailAddress("your.email.address#example.com", "Your name");
MailAddress recipientsMailAddress = new MailAddress("the.recipients.email#example.com");
message.To.Add(recipientsMailAddress);
message.Subject = "The subject of your email";
message.Body = "The body / content of your email";
message.IsBodyHtml = false; // You can set this to true if the body of your email contains HTML
SmtpClient smtpClient = new SmtpClient
{
Credentials = new NetworkCredential("Your username/email", "Your password"),
EnableSsl = true, // Will be required by most mail servers
Host = "The host name of the mail server", //
Port = 465 // The port number of the mail server
};
smtpClient.Send(message);
If you have a Gmail account, you can use their SMTP server in your C# application, simply use these settings and it should all work.
Hostname: smtp.gmail.com
Port: 587
Username: your_email#gmail.com
Password: ********
RequireSSL: true
Have a look at SmtpListener, I think it does what you want.
It isn't a standard email server which will receive new emails throught SMTP, store them on disk and allow you to retrieve them using POP.
SmtpListener will create a SMTP server that will receive email and allow you to react to any new email through code.
However, please note that you will have to configure it in your production environment like a real SMTP server, including MX DNS entries.

SMTPClient sending limit of 50 emails when using third party vs drop folder

I have an application that needs to send out a lot of emails on occasion. Most of the time, it sends approx 30 emails. It has no problem with this. On occasion though (once per month), it needs to send more than 50 (hundreds, not thousands).
When testing using a local drop folder, the SMTP client works fine and I can see all emails land in my drop folder.
When testing using Mandrill (the actual ESP), MandrilL only seems to receive 50 emails. This is consistent always.
Each email to be sent gets its own SMTPClient instance.
I've tried processing the emails in parallel and sequentially. Both behave the same.
Code that sends each individual email:
private static void Send(MailMessage mail)
{
SmtpClient client = new SmtpClient();
client.SendAsync(mail, null);
}
Each email has a single recipient.
ESP (Mandrill) reputation is high and sending limit is 1453 per hour. This is barely dented.
Can you suggest where this limit of 50 is being imposed (SMTP config, ESP config, other) and how I can remove (or increase) it?
If all of the message bodies are the same, you can just add all of the recipients to the Bcc (Blind Carbon Copy - meaning that none of the recipients can see who else got the message) list and send the message once and have it be sent to all 50+ recipients.
If they aren't the same, simply reuse the same connection to send those 50+ emails.
The problem is probably that your SMTP server throttles incoming connections to 50 per hour or some other window of time to discourage DDoS.
Just because the server allows 1453 messages per hour doesn't mean you can connect to it 1453 times per hour.

Delivery Notification in SMTP

Below code is workin fine . However I need get Failure or Success Notification to Specific address (b#technospine.com). But I'm receiving Delivery Notification mail to FromMail address(A#technospine.com). Can you please help me to resolve this problem?
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("A#technospine.com", "BALA");
MailAddress adminAddress = new MailAddress("b#technospine.com");
smtpClient.Host = "Mail Server Name";
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = true;
message.From = fromAddress;
message.To.Add(_sendTo); //Recipent email
message.Subject = _subject;
message.Body = _details;
message.IsBodyHtml = true;
message.Headers.Add("Disposition-Notification-To", "b#technospine.com");
message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
message.ReplyTo = adminAddress;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Send(message);
The short answer is what you are asking cannot be done in the direct manner in which you are assuming.
This will only work in certain conditions. The easiest to describe would be if the SMTP server you are using to send the message, is the same server that hosts the domain of the recipient email messages (the server you refer to when setting your .HOST property of smtpClient). So, if you were only sending to recipients on your local SMTP mail server, then this might work pretty reliably. But that depends on the specific SMTP server software being used and potentially also on how it is configured.
To explain why this is, you must realize that only the last SMTP mail server receiving the message that actually hosts the desired email addresses, will be able to authoritatively answer the question, is this a valid email address. If the message has to pass through any other email servers on the way to getting at this final authoritative server, the message has to be handed off sequentially from one server to the next server in the chain until it reaches that final authoritative server. This means that there is not a guaranteed method for authenticating a specific address. Couple this with the fact that some domains are configured to act as a black hole and swallow illegitimately addressed mail, and you can see that there are many reasons why you cannot rely on that methodology.
So, many messages to external domains are going to have to hit at least one separate SMTP server and depending on how that server answers or forwards the mail, it will determine the results for any specific receiving domain. In fact, monitoring the FROM address for bounced messages is not foolproof either as my previous comment about some hosts putting some messages into a black hole if they do not appear to be valid.
If the recipient e-mail address is valid you don't get an immediate return value about the successful delivery of the message; see the signature:
public void Send(MailMessage message)
The SMTP server will notify the sender (or whoever you specify for the notification) almost immediately with an 'Undeliverable' notification whenever the recipient e-mail address is invalid/fake.
SMTP servers are required to periodically retry delivery. When the recipient e-mail address is a valid address but for some reason the SMTP server could not deliver the message, the SMTP server will return a failure message to the sender if it cannot deliver the message after a certain period of time.
RFC 2821 contains more details.
From section 2.1 Basic Structure
In other words, message transfer can occur in a single connection
between the original SMTP-sender and the final SMTP-recipient, or can
occur in a series of hops through intermediary systems. In either
case, a formal handoff of responsibility for the message occurs: the
protocol requires that a server accept responsibility for either
delivering a message or properly reporting the failure to do so.
See sections 4.5.4 and 4.5.5
From section 6.1 Reliable Delivery and Replies by Email
If there is a delivery failure after acceptance of a message, the
receiver-SMTP MUST formulate and mail a notification message. This
notification MUST be sent using a null ("<>") reverse path in the
envelope. The recipient of this notification MUST be the address from
the envelope return path (or the Return-Path: line).
According to MSDN the .Send will throw a SmtpFailedRecipientsException EDIT: if the MESSAGE can not be delivered to one or more of the recipients. You can find the information on which one in the Failed Recipient property in the exception.
Thus if you try and catch that exception and validate the address you're looking for in the Exception, that might help.

Troubleshooting "421 Connection not accepted at this time" error when sending email with SmtpClient

I am trying to send 4 emails using my isp. (NOT JUNK MAIL, i send it to my address)
I send them one by one from a loop (as I build them). every message is 50kb-80kb
MailMessage mailmessage = new MailMessage();
mailmessage.To.Add(to);
mailmessage.From = new MailAddress(from, "From");
mailmessage.IsBodyHtml = true;
mailmessage.Priority = MailPriority.Normal;
mailmessage.Subject = subject;
mailmessage.Body = body;
SmtpClient smtpclient = new SmtpClient(server, 25); //use this PORT!
smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpclient.Credentials = new NetworkCredential(user, pass);
smtpclient.Send(mailmessage);
On last message I get this error:
Service not available, closing
transmission channel. The server
response was: Connection not accepted
at this time
UPDATE:
some times after this error , I can't send any email (using this server) even from other applications like outlook express, I get error:
An unknown error has occurred.
Account: 'MailServerAddress', Server:
'MailServerAddress'', Protocol: SMTP,
Server Response: '421 Connection not
accepted at this time', Port: 25,
Secure(SSL): No, Server Error: 421,
Error Number: 0x800CCC67
after about a minute, I can send again.
Always make sure your sender address is also a valid mailbox so bounce messages actually get back to you, many ISPs prohibit use of other (unregistered) sender addresses entirely. As pointed out in the comments by others, there is typically also rate limiting by the ISP so you'll have to fine-tune your sending code to the ISPs expectations, which can be tedious.
In general, sending emails is both art and science for some reason. If you're trying to use this for a production system, I can only suggest you use some service such as SendGrid or Mailgun. Even if your mail server accepts the messages, it might hit a limit on another ISPs mail server because most ISPs have certain limits and email routing is quite complicated. Also you might hit spam filters quickly. With my ISP, automated messages always to go spam in googlemail for whatever reason.
For development, Mailgun offers a two hundred emails per day for free which should be enough in the beginning. Also, SMTP is a very slow protocol so using their HTTP interface will save you some server time.
I had not exactly, but very similar issue here:
SMTP send email failure by SmtpClinet (SmarterEmail server)
The problem was that my local ISP was closing 25 port.
Have you tested some other ports, like 587?

Check for new mails in Hotmail using OpenPop.NET

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.

Categories