I am using this code to send an SMTP email via the yahoo SMTP server, it is for a personal project I am writing.
using System.Net.Mail;
using System.Net;
SmtpClient theClient = new SmtpClient("smtp.mail.yahoo.com", 465);
theClient.UseDefaultCredentials = false;
theClient.Credentials = new NetworkCredential("username", "password");
theClient.EnableSsl = true;
MailMessage theMessage = new MailMessage("[email protected]",
"[email protected]");
theMessage.Subject = "Dave test from C# subject";
theMessage.Body = "Dave test from C# body";
theClient.Send(theMessage);
It's all pretty standard code for sending SMTP email, but... the server seems to throw an error. It forcibly terminates the connection. This does not happen if I use other SMTP servers like Gmail, Windows Live or various other ISP Smtp servers.
This is the exception and stack trace:
System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at ConsoleApplication1.Program.Main(String[] args) in E:\dev\ARCSoftware.FTPProcessor\ConsoleApplication1\Program.cs:line 28
I know the problem is not environmental though as I can send to the same server with these exact settings using Outlook Express. I am wondering if I need to send a certificate or something?
If you, or anyone you know where has any ideas about this I would greatly appreciate some help.
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
Originally Answered: What is the full form of C ? C - Compiler . C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972.
The letter c was applied by French orthographists in the 12th century to represent the sound ts in English, and this sound developed into the simpler sibilant s.
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
using System.Net.Mail;
using System.Net;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void btn_Send_Click(object sender, RoutedEventArgs e)
{
MailMessage oMail = new MailMessage(new MailAddress("[email protected]"), new MailAddress("[email protected]"));
SmtpClient oSmtp = new SmtpClient();
oSmtp.Host = "smtp.mail.yahoo.com";
oSmtp.Credentials = new NetworkCredential("username", "password");
oSmtp.EnableSsl = false;
oSmtp.Port = 587;
oSmtp.Send(oMail);
}
}
It's not supported through 465, but the following post details a workaround
How can I send emails through SSL SMTP with the .NET Framework?
UPDATE: This link details why it might work through Outlook Express, but not through the System.Net.Mail
http://blogs.msdn.com/b/webdav_101/archive/2008/06/02/system-net-mail-with-ssl-to-authenticate-against-port-465.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With