SmtpClient error when recipient list is 101 email address - c#

Is there any limitation on the size of the recipient list? I have a simple program that read the email address from the database and sends out an email with an attachment.
It works FINE when I test it with just 3 email address but I get the below error when I use the complete recipient list of 101.
Unable to read data from the transport connection: An established connection was aborted by the software in your host machine.

It's hard to tell by just what you provided but you should be aware that when you're sending an email to an SMTP server, it looks at the recipients before accepting all of your data and it does a lookup for each email address before it continues. Sometimes, SMTP servers are a bit slow with the lookup and tend to time out. That could be your issue and if it is, it's pretty much out of your control unless you own the mail server and you can tweak it in some way.

Related

C# SMTP message transfer to recipient through MX Record

I know there many articles on web regarding sending emails from code/C# and I have read many of them before posting here, but I still don't see a clear picture of how to implement my requirements:
Scenario:
My application on mydomain.com receives a request to send some kind of email (from: someone#mydomain.com, to: someone#gmail.com/anyother.com).
I need to make some manipulations on email content.
After I modified a message, I need to send it directly to recipient.
Under directly to recipient I mean that I want to send it to recipient by our servers and not using some kind of SMTP service/relay.
So as I understand I can install some SMTP software on our servers and send using System.Net.Mail.SmtpClient to our server and it will deliver it to recipients using SMTP Relay or some other way that coded inside that software...but, I would like to make it without using SMTP Server software...
Till now I found that I need to discover MX record for recipients domain, so let's say I found MX record for gmail.com (gmail-smtp-in.l.google.com), but how do I send email to that MX Record from my own C# code?
Does System.Net.Mail.SmtpClient suitable for this task?
Where I can find examples of how to do it?
From my previous expirience with SmtpClient, I need to provide SMTP server address (optionaly port), credentials, but in my case, of course I do not have credentials and I'm not sure how to get the correct port (does all servers from MX records has port 25?).
Thanks!

Why Gmail SMTP Stopped Working?

I wrote a windows base application with C# which sends email from a unique address to another unique address every 5 minutes using google smtp. I installed it in 5 Systems of my Company.
It worked for about 500 messages.
today I recieved a "delivery failure" message and it stopped working.
the message was
Delivery to the following recipient failed permanently:
my email address
Technical details of permanent failure:
Message rejected. See http://support.google.com/mail/bin/answer.py?answer=69585 for more information.
I know Gmail blocked my address. but Is there any way to reactive it? I just using two email addresses.
From what I understand, you are using the first email account to broadcast a message, and the second email account to receive those message, which is a lazy way to solve the issue you have at hand and is prone to problems just like the one you've just witnessed. Sending out 500 notifications to a single email address, from a single email address will always raise red flags.
You have two options, you can either carry on using SMTP by using a different service provider and risk service disruptions as well as having your IP being blacklisted or you can create a simple API which the client applications can subscribe to.

How can I get the SMTP host name from email address?

I was working on an application which would send emails automatically at specific time intervals to a valid email. Searching through the internet I found that most of the codes use the existing email accounts such as gmail.com to send email by logging in as an SMTP client. But my problem is that I won't be knowing the smtp server name of the users email(since the user is not generally aware of these things though he will be knowing the login/passoword). For example,
someone#gmail.com should give smtp.gmail.com and port number (465)
someone#nextek.net should give mail.nextek.net and port number (?)
someone#screaming.Net smtp.tiscali.co.uk and port number (?)
I got the MX records using the domain name of the email address, but I realized that it actually gives the available incoming SMTP server names.
For example gmail.com would give gmail-smtp-in.l.google.com along with four other server name if I ping using nslookup in command prompt.
Also what is the advantage of sending email by using an existing SMTP supporting email than sending directly by looking up the email server name through dns? Or is it not possible?
Correct me if I am wrong, since I am not much familiar with the protocols.
If you're not familiar with the protocols, it doesn't make sense for you to try to implement the protocol.
Generally, an application like yours doesn't need to worry about the details of the SMTP protocol. You would use an existing SMTP client library for your platform (I'm sure there is one for .NET you can use), and connect to an MTA (your MTA, not the recipient's), give it the email to send, and you're done. The MTA will take care of all the SMTP protocol details of figuring out how to get the email to the recipient.
Sending email is very similar to dropping a letter in the post box on the corner, and letting the post office figure out how to deliver it. You don't need to know which vehicle to put it on, or where the recipient's local post office distribution centre is, or any of those details.
You may choose to set up your own MTA using something like Postfix, or you can send email through your own Gmail account (of course you'll need a Gmail account and password before Gmail will let you do that).

"Failure sending Mail" error on program

my friend gave me a program which runs in his laptop, he coded with system.webmail and C#, that program can send the email in his machine, but when i run and send it out in my machine, the email didn't send and get "Failure Sending Mail", but in his computer, he can send with his internet. But I am still getting error, even i can't ping to SMTP server or telnet. What will be issue, does my ISP ban the port, or ISP firewall ban the port?
I use port 25 and also 587 too. but it doesn't do any different at all.
There is an unfixed bug in System.Mail.SmtpClient where sending mail to a domain-enabled (Exchange) server fails if you cannot domain authenticate, even if username and password would authenticate, but only if you are farther than ~10ms from domain server.
I have a same issue before and it turned out that the email provider "Smart Mail" is blocking my email, The solution I simply added the email address at the safe list in my destination email.

Sending an email in C#

Is it possible to send an email in C# console, without needing and SMTP server?
Edit:
Why do I need another SMTP server? Can not I use my localhost machine as a server..?
Edit:
I just need to send an email from with my domain name, for example abc#mydomain.com
Is that possible? what do I need to do this in my C# program... I do not care about receiving emails, I just care about sending them....
Thanks
You don't have to depend on a local SMTP server if you don't have one. However, you will have to connect to a SMTP server anyway. Here is why.
You must achieve the following steps:
Determine what is the mail exchange servers of a given domain.
Connect to that mail exchange server and deliver your mail.
Those steps are normally done by your local SMTP server. Another advantage of your local SMTP server is that it will handle its queue and continue to try to deliver your email if it fail.
How to determine the MX records of a give domain.
I suggest you to have a look at this answer. Basically, you have to do a query on a DNS server to get the list of MX records of the domain name of the email address you want to send an email to.
How to connect to a mail exchange server
Well the answer will disappoint you. Exactly like you connect to your local SMTP server. Using the TcpClient, you connect to one of the mail exchange server you got at the previous step on port 25 and start the delivering process using the SMTP protocol.
The trick here is that you must handle multiple MX servers. They are usually listed with a preference. If the first one is unreachable, you try the next one and so on...
That is something your SMTP server can handle for you too.
If you really want to build that logic yourself, please have a look at the DirectSend method of the SmtpClient class of this open source project I'm involved in.
As #TomTom points out, the entire mail infrastructure depends on SMTP. What you can do is to skip the output (relaying) SMTP server and send the message directly to the receiving SMTP server.
To do that you need to create some kind of queuing mechanism (there is no guarantee that the receiving SMTP server can serve you when you try to connect) and that you can look it up.
MX records are entries stored in DNS servers and are used to find SMTP servers. You can find a article here with a MX lookup example: http://www.codeproject.com/KB/IP/dnslookupdotnet.aspx
However, I DO recommend that you install a local SMTP server and let it take care of the above mentioned issues.
Yes, Basically figure out where to sent the email and send it. i.e. a DNS MX lookup for the domain to find out the SMTP server.
Every email needs an SMTP server on the receiving side.
You can use gmail or yahoo SMTP server, if you don't want to install your own.
Before sending mail you first need to authenticate, otherwise sending mail is not going to possible.
You need access to some kind of email server to send your email, and your email will most likely pass through one or more SMTP servers on it's way to the recipient. However, the email server you connect to might let you send the email without using SMTP. For example, Exchange might let you use MAPI or CDO to send emails. Though I think that CDO is not officially supported by .Net and simple MAPI is deprecated in Windows and should not be used. You might be able to use Exchange Web Services as described here: Introducing the Exchange Web Services Managed API 1.0
If you have another email server than Microsoft Exchange, that server might have some kind of API you can use.
Something I do often is to create gmail account and send through that account.
You just need your SmtpClient to connect to the host smtp.gmail.com on port 587 with the username, password, and enableSSL property set to true.

Categories