I created a new email box for general support questions. When I try to send an email through SMTP I receive the following error:
Mailbox unavailable. The server response was: No such recipient
I am able to email the box through Outlook and SMTP works when I send to other email address in the same domain.
The great thing about SMTP is that it's easy to spoof the conversation. The terrible thing about SMTP is also that it's easy to spoof the conversation. What makes this great is that if you want to figure out what's going wrong in a SMTP connection you can just "telnet mailhost 25" and start issuing SMTP commands like:
HELO example.com
MAIL FROM: <me#me.com>
RCPT TO: <him#him.com>
DATA
Subject: test message
From: Me <me#me.com>
To: Him <him#him.com>
test message
.
QUIT
Is your DNS configured properly? You need an MX record specifying which host handles incoming messages for that domain.
Btw, your post is missing some details, like which server you are using etc. That makes it hard to find where the problem is.
If you post the complete SMTP conversation (or at least what your client is sending) the answer will probably leap out at you.
Or, if you're speaking SMTP correctly, perhaps you're connecting to the wrong server. Does your client look up the DNS MX record to find the right SMTP host?
First, make sure the address is valid. Also, make sure the From address is valid (that may be your problem). Finally if those do not work, you should try setting the SMTP server explicitly.
Without a bit of a code sample, that's the best advice that I can come up with.
Does your company have multiple mail servers? No such recipient might be returned if you have multiple servers and the newly created account hasn't been pushed through yet.
I actually used Telnet to diagnose the problem (Thanks to Paul Tomblin for his post). I found out that our SMTP server uses GroupWise (we use Exchange as our main email client). I had to set up the address to relay to the GroupWise server as well.
Related
I've looked at 3 or 4 questions here so far and they haven't helped yet.
I have set up SmarterMail 14.x on a client's machine. I know very little about setting up mail servers (I don't know why he thinks I do) but I have it installed, a domain set up pointing to the MX record, the port open (9998) and I am able to send email just fine from the web interface.
However, I can't send email from Sql or from C#. I created a quick and dirty app to allow me to enter the server, port, credentials, and to/from and I get this response every time:
[Inner Exception]
Unable to connect to the remote server
[Details]
System.Net.Mail.SmtpException: Failure sending mail. ---> > System.Net.WebException: Unable to connect to the remote server ---> > System.Net.Sockets.SocketException: No connection could be made because the > target machine actively refused it 204.12.49.188:25
I've tried multiple logins. I've also confirmed that SMTP is turned on and IMAP/POP3 is turned off. I'd post images of it but unfortunately I can't yet.
The code to send is below and it is about as simple as it gets:
SmtpClient client = new SmtpClient(ServerTextBox.Text, Convert.ToInt32(PortTextBox.Text));
NetworkCredential login = new NetworkCredential(UsernameTextBox.Text, PasswordTextBox.Text);
client.Credentials = login;
MailMessage message = new MailMessage(FromTextBox.Text, ToTextBox.Text, "Wine and Spirits Jobs Alerts", "Below are this week's job alerts: There are no job alerts at this time");
client.SendCompleted += HandleSendCompleted;
client.SendAsync(message, null);
I've also tried it locally on their VPS and on my machine. I've turned on and off the firewall and I've got a specific rule allowing outgoing traffic on 9998 (and you can log into the web interface remotely) so this isn't a matter of being able to contact it.
I'm at a loss of what to do. If someone can help??
EDIT: It's clear I was using the wrong port - 9998 instead of 25. Using port 25 now tells me either time out or that it was actively refused. The firewall does have specific rules for port 25 that allow all traffic, so it shouldn't be stopped.
EDIT 2: I've re-created the MX record on the domain and ensured it is pointing to the correct IP address. I've also re-created the domain in Smartermail and made sure SMTP is turned on, authentication is required, SSL is not, POP and IMAP are turned off, and that my login is correct. I've also tried turning on and off the firewall. No dice.
I finally solved the issue.
It had nothing to do with firewalls or the MX record or using/not using an IP address and everything to do with the fact that while port 25 was indeed assigned to SMTP and SMTP was indeed turned on, the IP address of the domain itself was NOT assigned to the SMTP configuration so SmarterMail wasn't actually monitoring the port.
Problem solved - email sends. Fun stuff! Thank you for everyone's responses!
Try setting SMTP mail server IP address in your mail sending code.
SmtpMail.SmtpServer = "your mail server name or IP address goes here";
SmtpMail.Send(Message);
Your can set this property at global level or in any Initialization code.
Reference : https://msdn.microsoft.com/en-us/library/system.web.mail.smtpmail%28v=vs.110%29.aspx
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.
I know that this question looks like duplicate of dozens other questions while its not.
When ever i try to send an email on my local machine through my web application an SMTPException is thrown and the exceptions is :
//on this line : SmtpServer.Send(mail);
Unable to read data from the transport connection: net_io_connectionclosed.
While the code on production is working perfectly, the same code, the same connections, the same credentials, i'm using IP instead of alias, i tried to turn off the firewall on my local machine, and nothing helped me to fix this issue.
While on my local machine is used to work previously, can anyone give just a hint what could be the problem that raising this issue?
If you are on a residential internet connection, quite often your ISP will block outgoing email sends by blocking all outbound connections to port 25. This is quite common here in the US. Try connecting to a local email server over TCP/IP, or to one on your own internal network.
This thread contains some.
For instance: it looks like assigning a static IP might solve the problem.
What this error means is that System.net.mail was unable to find the
smtp server.
The answer will vary depending on whether you have a fixed IP or a
dynamic IP but, basically, you need to assign a valid IP to your smtp
server.
With fixed IP's this is relatively straightforward. With dynamic IP's
it takes a bit of tweaking.
Open the IIS Manager and check the properties for the smtp server.
In the Default SMTP Virtual Server's properties, in the "Access" tab,
in the Connection Control and Relay dialogs, make sure that your local
IP is assigned. ( In my case, it's 10.0.0.2... )
You may also need to modify your hosts file, to point 127.0.0.1 to
your machine name. ( \WINDOWS\system32\drivers\etc\hosts )
Then, in your code, assign your machine name to the smtp client :
Dim client As New SmtpClient("yourmachinename") client.Send(mail)
Alternatively another guy in the same thread seems to have found a workaround for the SMTP connection not being correctly closed.
Set SmtpClient.ServicePoint.MaxIdleTime = 1 according to a supported
work-around:
http://connect.microsoft.com/VisualStudio/feedback/Workaround.aspx?FeedbackID=146711
which makes all smtp work properly.
Here's a complete sample:
MailMessage msgMail = new MailMessage();
msgMail.To.Add(new MailAddress("info#somedomain.se"));
msgMail.Subject = "Message from web";
msgMail.IsBodyHtml = true;
msgMail.Body = "Test message";
SmtpClient Client = new SmtpClient(); /* uses settings form web.config */
Client.ServicePoint.MaxIdleTime = 1; /* without this the connection is idle too long and not terminated, times out at the server and gives sequencing errors */
Client.Send(msgMail);
msgMail.Dispose();
System.Net.NetworkCredential(user, password); ///Wrong
System.Net.NetworkCredential(email, password); ///right
because some email server is shability
In my case, I had to leave out the Domain property from Network Credentials when setting username and password
The Gmail account you are using has limit for number of emails being sent out per day/month and if you exceed that limit, it will reject any further outgoing emails.
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 know it is possible to send an email with a fake address to impersonate someone else. I seen automated emails coming from my friend email address that he sent to me but did not write himself.
I know email servers ask the email provider if they really sent the message and if it is no it tends to go into spam or is marked untrusted. How do i access this data in my app? I havent chosen an imap library and thats because i dont know which may support this.
This functionality is not supported by imap.
Some servers store information like this in the header of the mail (like spamassassin info or SPF checks) so that is available with any imap library but depends highly on the mail server the app is connecting to.
In general it's not possible with IMAP. IMAP is intended for reading email, not for sending. You may try to fake email sender when sending email via SMTP protocol.
This is exactly what spam senders do (and what mail servers tries to detected).
It used to easy. SMTP dialog follows:
S: MAIL FROM:<your.friend#example.com>
R: 250 OK
S: RCPT TO:<somene#example.com>
R: 250 OK
S: DATA
R: 354 Start mail input; end with <CRLF>.<CRLF>
S: Blah blah blah...
S: ...etc. etc. etc.
S: <CRLF>.<CRLF>
R: 250 OK
But now things are getting more interesting. There is still race of arms between those two - for example:
Attack
Try to submit false "FROM:" address during communication with SMTP server.
Defense: SMTP server may require you to authenticate and allow only 'from' address associated with your account.
Another attack
Try to use third party SMTP server that has no such rule.
Defense (third party SMTP server): Allow sending only emails with 'from' domains matches with 'own' domains.
Defense (recipient's SMTP server): Add SPF record to your domain. This records includes all hosts that are allowed to send email with sender in this domain. If the email is sent from not allowed host increase it's spam score or delete it.
Another attack
Infect computer which is allowed to send email for specified domain with virus and send emails using it.
Defense: Educate users and/or use good antivirus.
And so on... There will be always ways how to fake sender's email address and how to fake it. Check following links for more info:
RFC 821 - SMTP
So You'd Like to Send Some Email (Through Code)