This question already has answers here:
Testing SMTP server is running via C#
(5 answers)
Closed 9 years ago.
I had web application that users can set SMTP server information (server/host, SMTP Port, Username, Password, EmailAddress, usedSSL). i need when user set information validatre server without sending email and check Is smtp information valid or not?
I found website that works perfect and check is SMTP server alive (but not authentication check).. http://mxtoolbox.com/diagnostic.aspx
Edit 1:
Tanx #Dieter DHoker help me to find Testing SMTP server is running via C# in comments...
Is there anyway that i check authentication information (username & password & email address) as i need to check all smtp information is valid or not? that i asked before..
There's no username and password in SMTP (see rfc 821), so there's no way to test that.
You could use a MAIL FROM and RCPT TO sequence, but not send any DATA, to see if you'll be allowed to send mail with the given information, without sending an actual mail.
Related
I am trying to send an e-mail using c# MailKit SMTP (code below).
It connects successfully (with Connect method) and then it fails on Authenticate method call with an error " Username and Password not accepted.". I know the user name and password are correct. I also tried "mail.optusnet.com.au" server on port 25 - same story.
What is wrong with my call to smtp.Connect method. I have spent whole day experimenting and got nowhere. Can somebody help please.
// send email
using var smtp = new SmtpClient();
smtp.Connect("smtp.gmail.com", 587, SecureSocketOptions.StartTls);
smtp.Authenticate("rejkid#gmail.com", "Password1");
smtp.Send(email);
smtp.Disconnect(true);
Google no longer allows your password to be used when authenticating via SMTP, POP3 or IMAP.
You either need to use OAuth2 or you need to enable 2FA on your Google account and then generate an app-specific password and use that.
I am trying to convert our current email agent to send email with TLS. We use C# and I just used the following changes.
SmtpClient sclient = new SmtpClient();
sclient.EnableSsl = true;
and a callback method to validate server certificate.
On Testing the mail was sent/received successully, but both I and the receiving end cannot be 100% sure the the email was received encrypted. (I tried to use Fiddler but its not capturing the email)
Based on this http://luxsci.com/blog/how-you-can-tell-if-an-email-was-sent-using-tls-encryption.html, and the header as below
with ESMTP id s7JKErN9002462
(version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO);
Can we safely assume that the mail communication indeed was encrypted? or Should I make any other code changes so that I can be sure that the email is received or it failed? (I think this cannot be certain as it depends on the smtp host) ?
In the end you can always check the TLS connection using network sniffer software such as WireShark.
Of course if you only leave a connection open to the SSL port of the server, and you receive the server certificate, you can be pretty certain the mail did not appear from the blue sky anyway.
You can safely assume that if you are able to connect and send, that the tunnel you're delivering the mail to is secure.
The SmtpClient code is solid and you can trust it. If it fails to connect securely after you've asked it to, it throws an exception, so you'll know something is not like you were expecting.
It seems that when you use SmtpClient class and MailMessage to send emails, everything works fine. And it does send it. However, some servers, such as your business Exchange Server or Gmail.com or whatever services, sometimes reject these emails (because they could be phishing sites or spam sites?)
I'm using this and a lot of places reject the email I believe:
SmtpClient smtp = new SmtpClient
{
Host = smtpClient,
Timeout = 40000, // 40 seconds
DeliveryMethod = SmtpDeliveryMethod.Network
};
How do you work around this? Do you have to use login credentials to some recognized / white-listed server so that it is authorized and trusted email?
I could use something like GMAIL authentication, but my server should be allowed to send emails, it shouldn't have to rely on gmail.
Long ago there were many servers on the Internet that provided the service delivery of e-mail without asking too many questions about who was using the service.
Then came the SPAMMERS!.
A server that was sending mail freely around the world was no longer a benefactor of the internet, but a problem.
Nowadays it is increasingly difficult to find a server that sends mail on the Internet without asking for credentials.
Your e-mail server (smtp.yourbusiness.com or whatever you want) does not trust you.
When you ask it to send an email for you, it wants to know who you are.
SmtpClient smtp = new SmtpClient
smtp.Host = "smtp.yourbusiness.com";
NetworkCredential credentials = new NetworkCredential("your_user_name_on_smtpserver", "your_password_on_smtpserver");
smtp.Credentials = credentials;
are you setting the sender mail address and can your mail server be resolved by reverse dns lookup? Some spam filters distrust mail servers they can't reverse lookup. If you for instance make your mail server send mails using a bogus or foreign mail domain, spam filters will probably pick this up and filter your mail. If you have set up a SPF record for your domain and your sending mail server isn't in that record, mails from that server will also often be filtered by spam filters. Another reason could be an IP address from a range known to be dynamically assigned by internet providers. Mail servers sending from these address ranges are mostly spam bots and are therefore often also filtered.
To send GMail you need to specify a number of settings - yes you'll need to use authentication (GMail wouldn't open up their relay to everyone, or they'd get used for spamming).
If I recall correctly you need to send on TCP port 587, enable SSL, host to mail.google.com and provide a username and password on your SmtpClient to get Gmail to actually send it - neglecting one of those usually generates an email back from them telling you what you've forgotten.
Edit: Just to clarify on the username and password bit; you'd need to create a new NetworkCredential with the username and password for your GMail account, and set the Credentials property of your SmtpClient to that.
If i interpret your question correctly: the messages are sent our from your server, but they are trapped in the spamfilters at the receiving end?
If this is the problem, it has nothing to to with the way you are sending the messages but much more with the content of your message and the characteristics of your server. So it does not matter what credentials you use or if you send it with SmtpClient or any other class. Moving to Gmail does not help and Gmail has a limit to the number of messages you can send.
Spam filters like spam assassin use rules. Match too many: your message is considered spam.
Have a look here for an example:
http://spamassassin.apache.org/tests_3_3_x.html
So make sure your message does not get too high a score and it will go trough.
I am working in C# Email Sending.
I have no problems sending programmatic emails via SMTP using the normal e-mail address like 'myemail#exchange.com'.
But as per Company Policy, whenever they send e-mails outside the network, they add a postfix on the e-add like "myemail#exchange.com#yodachi".
So when I tried sending using that e-add format I get the error: The specified string is not in the form required for an e-mail address.
Any suggestions would be greatly appreciated.
Note: I am using SmtpDeliveryMethod.Network since we are using SMTP thru company network.
Thanks,
Al
Edit: I've found out that the policy I am talking about is Lotus Domino Roaming. The postfix serves as a request on the Main Server to transfer a outgoing mail.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How to check if an email address exists without sending an email?
Hi All,
I have a email functionality in my asp.net Web Application, Email Addresses are taken from a database. Is it possible to check whether E-Mail address really exists OR not. How can I do it ?.. I have searched in forums and Google got some related info which says using VRFY, RCPT Commands... but I didn't understand how can those commands be used in .NET using C#.. There are some third party tools but my client will not buy those tools..
I have SMTP mail server details,, ?? Is there any way this can be achieved ?
The only way is to open an SMTP connection and first try the VRFY, if this results in no, it does not exist, BUT if it is Yes it might only be that the server do not tell so the second step is to send the commands to send an email but after RCPT TO you abort, do not send the data command as some servers might actually send the email then even if you abort.
If it does not protest after RCPT TO you might as well try to send for real because that will then be the only way to test further, but some servers will accept the address and only fail later or even fail with a return message that will not be detected in the SMTP session at all.
So you cannot 100 % test an email without actually sending to the address and have the recipient either return the email to you or click a link to confirm the address.