Impossibile verificare l'invio di e-mail dal codice .NET in Windows Vista Business."Impossibile leggere i dati dalla connessione di trasporto: net_io_connectionclosed." - Windows Vista Business e SMTP
Sto scrivendo il codice che migrerò a un pacchetto SSIS una volta provato. Il codice è quello di inviare un messaggio di errore via e-mail a un elenco di destinatari.
Il codice è di seguito, tuttavia ricevo un'eccezione quando eseguo il codice.
ho creato una semplice classe per fare la mailing ... il design potrebbe essere migliore, sto testando le funzionalità prima di implementare funzionalità più robuste, metodi, ecc
namespace LabDemos
{
class Program
{
static void Main(string[] args)
{
Mailer m = new Mailer();
m.test();
}
}
}
namespace LabDemos
{
class MyMailer
{
List<string> _to = new List<string>();
List<string> _cc = new List<string>();
List<string> _bcc = new List<string>();
String _msgFrom = "";
String _msgSubject = "";
String _msgBody = "";
public void test(){
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("[email protected]");
//set the content
mail.Subject = "This is an email";
mail.Body = "this is a sample body";
mail.IsBodyHtml = false;
//send the message
SmtpClient smtp = new SmtpClient();
smtp.Host = "emailservername";
smtp.Port = 25;
smtp.UseDefaultCredentials = true;
smtp.Send(mail);
}
}
Messaggio eccezione
Inner Exception
{"Unable to read data from the transport connection: net_io_connectionclosed."}
Stack Trace
" at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)\r\n at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)\r\n at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)\r\n at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)\r\n at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)\r\n at System.Net.Mail.SmtpClient.GetConnection()\r\n at System.Net.Mail.SmtpClient.Send(MailMessage message)"
Outer Exception
System.Net.Mail.SmtpException was unhandled
Message="Failure sending mail."
Source="System"
StackTrace:
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at LabDemos.Mailer.test() in C:\Users\username\Documents\Visual Studio 2008\Projects\LabDemos\LabDemos\Mailer.cs:line 40
at LabDemos.Program.Main(String[] args) in C:\Users\username\Documents\Visual Studio 2008\Projects\LabDemos\LabDemos\Program.cs:line 48
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at System.Activator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.IO.IOException
Message="Unable to read data from the transport connection: net_io_connectionclosed."
Source="System"
StackTrace:
at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
InnerException:
Non ho intenzione di fornire una risposta per questo semplicemente perché non ne so abbastanza su SMTP per sentirsi bene a riguardo. Tuttavia, questo sicuramente sembra un problema di ambiente (probabilmente nelle impostazioni di IIS). Stai usando 1) "localhost" per smtp.Host 2) un server remoto per smtp.Host e/o 3) un IP specifico piuttosto che un nome host? –
Il mio host di posta viene chiamato per nome. Esempio "scambio". Ho testato il DNS tramite il ping del server. Questo ha avuto successo. Ho anche testato l'accesso alla porta via telnet alla porta 25. Ciò ha avuto anche successo. Ho testato il codice su un'altra macchina e sono riuscito a inviare il messaggio. Mi sembra che ho bisogno di installare un certo tipo di servizio/protocollo SMTP sulla macchina. La macchina su cui è fallito il codice è Windows Vista Business. I test hanno avuto esito positivo su Windows Server 2008 Standard. –
fare riferimento a: http://stackoverflow.com/questions/13689265/net-3-5-smtpclient-failure-sending-email-works-only-after-restarting-everyt/14272912#14272912 –