Error on sending mail programmatically - c#

I am trying to send an e-mail from a simple console application using my company's mail server:
MailMessage mm = new MailMessage("myemail#mycompany.com", "myemail#mycompany.com", "test", "testbody");
SmtpClient client = new SmtpClient("mail.mycompany.com", 465);
client.Credentials = new NetworkCredential("myemail#mycompany.com", "myPassword");
client.EnableSsl = true;
client.Send(mm);
Console.WriteLine("email sent");
Console.ReadKey();
I am getting the following error: "Failure sending mail.", innerException is "Unable to read data from the transport connection: net_io_connectionclosed."
I have tried connecting to the mail server on that specific port via telnet, which was working fine. My login credentials were also tested on the webmail client and I was authenticated correctly. I have checked my firewall settings, and let Visual Studio through the firewall.
Any ideas what could cause the problem?
Regards,
Adam

Try setting the ssl to false and setting the port number to 25.
Also double check wether the smtp server is open, because then you won't need the login authentication parameters.

Related

Unable to connect remote sever (SMTP , Hosting Server)

I am trying to send mail through SMTP but i am getting the error unable to connect remote server, I have tried alot but still getting same error
I am hosted my site on Go Daddy,
please any body suggest me where i am wrong , or is there any settings on GoDaddy server to send mail from "relay-hosting.secureserver.net"
MailAddress fromAddress = new MailAddress(from);
message.From = fromAddress;
message.To.Add(toList);
System.Net.Mail.SmtpClient Client = new System.Net.Mail.SmtpClient("
relay-hosting.secureserver.net", 25);
Client.Credentials = CredentialCache.DefaultNetworkCredentials;
Client.DeliveryMethod = SmtpDeliveryMethod.Network;
Client.Send(message);
You are trying to send mail using remote SMTP server, but using credentials from your local environment.
Try to use another credentials class type to specify it more concrete:
Client.Credentials = new System.Net.NetworkCredential("yourusername", "yourpassword");
Referring to your code:
System.Net.Mail.SmtpClient Client = new System.Net.Mail.SmtpClient("
relay-hosting.secureserver.net", 25);
You're using port 25, which is actually the problem. System Administrators who utilize GoDaddy as their hosting provider may experience trouble sending mail over port 25. This is because GoDaddy requires their servers to send through their own SMTP Relay instead of any third party. This is really a frustration situation, but this is what Godaddy policy is. If you use Godaddy relay, then it will work.

Setting up SSL property while sending an email c#

Can any one suggest me the background code when selecting the following while sending an email.
I have two check boxes 1.This server requires an encrypted connection 2.My SMTP server requires authentication. So my question is what is the difference between these two(in code part).
You need to enable SSL in your SMTPClient object.
https://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.enablessl(v=vs.110).aspx
Example:
SmtpClient client = new SmtpClient("SMTP connection details");
client.EnableSSL = true;

Unable to send email via localhost

I am getting the following error:
Failure sending mail
and inner exception is
Unable to connect to the remote server
in C#
MailMessage mail = new MailMessage("you#yourcompany.com", "user#hotmail.com","Newsletter", "This is a test mail");
SmtpClient client = new SmtpClient("localhost");
client.Send(mail);
This is my local smtp email setting in IIS 7.
Also installed the smtp server tools
Try setting the "Email Address" field in the IIS SMTP settings to the FROM address you are using.
SOURCE

Relay access denied on sending email

I want to send email via my desktop app
Here is my code
MailMessage m = new MailMessage("mahmoud#isysway.com", "gavoh3d#yahoo.com", "subject", "body");
m.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("out.tedata.net.eg");
smtp.Credentials = new System.Net.NetworkCredential("mahmoud#isysway.com", "password");
smtp.UseDefaultCredentials = true;
smtp.Send(m);
My problem is: this code throw an exception
Transaction failed. The server response was: 5.7.1 <gavoh3d#yahoo.com>: Relay access denied
I think because my internet provider need outgoing server (SMTP) authentication
I config it in Outlook as below
Now, How can I config it in my code
Thanks
I found this question because I have the same problem. I solved it using the myNetworks entry in /etc/postfix/main.cf
Add the IP from which your sending to the myNetworks line, I think PostFix expects a space to separate IP adresses, for my eyes it's better to use a comma, but if I use both it works.
This solution is not ideal, so I'll be gratefull for a better one!
Rob
It can be various issues:
are you able to send mail to Yahoo mail from your outlook? check this link If yes
Check IIS SMTP Virtual Server Relay Restrictions
Hope this help you.

Unable to send SMTP mail with .NET, network issue?

I am trying to send an smtp email through gmail's smtp server using the code below:
MailMessage message = new MailMessage("myEmail#gmail.com", "myEmail#purdue.edu", "Testing SMTP", "Test, yo");
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Host = "smtp.gmail.com";
client.Port = 587;
client.Credentials = new NetworkCredential("myEmail#gmail.com", "myPassword");
client.Send(message);
Using the same code my friend successfully sent me an email from another network, but .NET throws the error "No connection could be made because the target machine actively refused it 74.125.91.109:587". This has to be a network issue right?
My network admin claims there are no blocked outbound ports and my firewall is entirely off, what else could be causing this? I have tried Purdue's smtp server as well (smtp.purdue.edu), and it fails with the same message.
Turn off any antivirus program.
Regarding the test to Purdue, are you sure that they use port 587?
You should use port 465 for SSL according to this
Change the port to 465. It worked for me.
This may caused by McAfee Virus Blocks the Mass Mailing Worms. you can do the following:
1.Open the VirusScan Console by right clicking the VirusScan shield in the system tray and select VirusScan Console...
2.Double click the Access Protection item and open it.
3.Uncheck the Prevent Mass Mailing Worms from Sending Mail rule.
4.Click OK and close the VirusScan Console.
Hope this is helpless.

Categories

Resources