sending email only works after connecting with telnet first - c#

I am trying to send emails from my dotnet 4.5 client and I have a strange problem.
the code I use is this :
MailMessage message = new MailMessage("me#here.com", "you#here.com", "blah blah blah", "whatever");
SmtpClient SmtpServer = new SmtpClient("relay.skynet.be", 25);
SmtpServer.EnableSsl = false;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.Send(message);
This returns no error but no email is being send.
Now, when I open a command prompt and do this:
telnet relay.skynet.be 25
from now on it works, and all the emails I tried to send before also arrive.
So my question is, why do I have to open a telnet session first before my dotnet client is able to send email ?
And what can I do to make it work without this ?

I am not 100% sure here, but as far as I understand, Look like telnet client not running on your system. But after running the telnet command it seems telnet started on your system and your system start communicating with telnet server.
Please correct me if i am wrong here.

Related

C# script task to send email out at end of SSIS process returns error: '4.3.2 Service not available' [duplicate]

I am getting this error while sending email from my application. Can anyone suggest any solution.
Service not available, closing transmission channel. The server
response was: 4.3.2 Service not available, closing transmission
channel
Below is code.
string adminID = "AAA#tu.edu";
MailMessage msg = new MailMessage();
msg.From = new MailAddress(adminID);
msg.To.Add("BBB#ttu.edu");
msg.Subject = "Sample Email";
msg.Body = "Hello ";
SmtpClient SmtpMail = new SmtpClient();
SmtpMail.Host = "basic.smtp.ttu.edu";
SmtpMail.Port = 25;
SmtpMail.Send(msg);
Got the solution for the issue. The Server was rejecting the request because this application didn't have write rights on that server. The code was perfectly fine, just it was permissions problem. Hope this helps someone!
Please check whether the server which is sending the e-mail is whitelisted on the SMTP server or Exchange server.
I had the same issue and whitelisting it on SMTP server resolved my issue.

Trying to send smtp email in C#. No errors but does not get received. PHP works

I have a server that runs IIS and PHP. I have numerous webpages that send emails, some to me, some to the users. This all works great. I am on a Comcast Business Class account which means I can use smtp.comcast.net as my SMTP server, use port 25, and not use any sort of authentication which is great. And it works just fine.
Now fast forward to today. I am writing some custom C# code to monitor a folder structure and basically email me the new file if it matches certain parameters. In my C# code, I try to use the same settings, but it doesn't work. The SmtpClient.Send() function does not throw an Exception and my code completes the routine as if everything is happy and working. But then I wait and wait and wait, and I never receive the email.
SmtpClient smtp = new SmtpClient("smtp.comcast.net");
smtp.Port = 25;
smtp.EnableSsl = false;
smtp.UseDefaultCredentials = false;
smtp.Timeout = 2500;
smtp.Send(mail);
onStatusUpdate("Successfully sent email to " + mail.To + (mail.CC.Count > 0 ? " and CC'd " + mail.CC.ToString() : ""));
The "mail" object is of type MailMessage and is setup with the To, From, subject, body, and CC. Also has HTML and Plain Text alternate views.
I guess the easiest question, is if there is a trick to sending email the oldschool port-25 way in C# that doesn't exist in PHP?
And the only reason I mention PHP is because I know my firewall isn't blocking port 25, I know my ISP has it open, I know I have the right server, I know it should work.
I don't know if this affects their Business Class accounts, but Comcast just recently (<2 months ago) closed off port 25 for all their email accounts. try using port 587
http://customer.comcast.com/help-and-support/internet/email-client-programs-with-xfinity-email/
The first place to look is in the mail server logs of the outgoing mail server that you are using to send this message. These should tell you whether or not the mail server is even receiving the message from your C# program for queuing, and if so - what's happening when it attempts to deliver the message to the remote MTA.
Well about 5 hours after I started testing, I got all my test emails at once including the embedded HTML and everything else. So it is working just as it should. I guess since the signature was slightly different they block them until they are deemed non-spam. It also appears that now when I send an email it goes through instantly.
So Comcast has some sort of time delay filter apparently for anybody else in the future with this problem.
I ended up adding mails to the (to list),
and put sending in foreach for every mail I send mail separately,
and it worked!

Not able to connect to SMTP port of server

I have following piece of code, usiong which I am trying to send an email. I am using another server as SMPTClient.
MailMessage message = new MailMessage();
message.To.Add(toEmailId);
message.Subject = "test Subject";
message.From = new System.Net.Mail.MailAddress("myid#xyz.com");
message.Body = "This is a system generated email. Please do not reply";
SmtpClient smtp = new SmtpClient("anotherservername");
smtp.Send(message);
While debuggin, I get error at last line. The error is:
An attempt was made to access a socket in a way forbidden by its access permissions SERVER IP :25
I found out from internet that My firewall might be blocking me to access that server's port, or is there any setting, configuration which I have missed. Apparently the applications deployed on that server are able to send emails. I am still building one to test.
Some servers perform authentication and authorization by checking if you've connected to POP server some time before connecting to SMTP. You should try first connecting and authenticating with POP and afterwards connecting to SMTP.
Historically, email clients first checked and then sent emails in Send&Receive routines, so this was used as poor mans authorization. Take a look at wikipedia article about POP before SMTP.
Another issue which caused this for some people is how server address is provided to SmtpClient. You should use constructor which explicitly provides port number instead of appending it to IP/hostname. I.e.
instead of new SmtpClient("123.123.123.123:25")
use new SmtpClient("123.123.123.123", 25)

WebMatrix Not sending mail now that it is moved to the server

I am trying to get WebMatrix running on a local server (simply for testing within our intranet), but it is having trouble sending mail where it never did before on my local (work) machine.
I am getting a simple, the operation has timed out message. The account for this is setup through gmail, so I wouldn't think that there would be too many problems, but as I have never set up WebMatrix on a server before, I don't really know how to attack this issue.
When I had the Email working in construction of this website, I used these settings and everything worked fine:
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.SmtpPort = 25;
WebMail.EnableSsl = false;
Then when I ran it with these settings on the server I got this error:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first.
With that, we tried to enable SSL, but get a simple response timed out request after that (using these settings):
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.SmtpPort = 465;
WebMail.EnableSsl = true;
The "Username" and "From" fields are set the same (name#somecity.net) this is an example of our email that is managed by gmail. Also the password is set and correct.
Am I chasing the wrong thing here, by looking into SSL?
You'll have to forgive me in that I have never implemented SSL before. I know what SSL is, but I have never set it up before, so I apologize if I am a kind of a noob when it comes to setting this up.
Also, just so you know for sure, the server error does, in fact, error on the WebMail.Send method.
You should change your SMTP port for the Gmail one. Right now, gmail is working with 587 instead of 465.
You can check it using telnet smtp.gmail.com 587. Then you should get something like this:
220 test.auto.mySMTPserver.com ESMTP Service (Lotus Domino Release 8.5.3FP2 HF95) ready at Tue, 30 Oct 2012 08:27:31 -0700
Your new code:
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.SmtpPort = 587;
WebMail.EnableSsl = true;
And that's it.
I would say that the message tells you you are not authenticated, so you are likely to need to send a username / password for a valid user on the server. See this question for an example of authenticating to a mail server to send.

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