C# (这个想法)
我的email类有两个属性,一个是Message(System.Net.Mail.MailMessage),另一个是Server(System.Net.Mail.SmtpClient),这就是本例中要处理的内容C# (这个想法),c#,.net,windows-vista,ssis,system.net.mail,C#,.net,Windows Vista,Ssis,System.net.mail,我的email类有两个属性,一个是Message(System.Net.Mail.MailMessage),另一个是Server(System.Net.Mail.SmtpClient),这就是本例中要处理的内容 在我的服务中发送电子邮件的每一个实例都以这种方式实现后,我收到了数百封电子邮件,但我没有遇到任何问题。我不打算为这封邮件提供答案,因为我对SMTP的了解不够,无法对此感到满意。但是,这听起来确实像是一个环境问题(可能在IIS设置中)。您是否使用1)“localhost”作为smtp.Ho
在我的服务中发送电子邮件的每一个实例都以这种方式实现后,我收到了数百封电子邮件,但我没有遇到任何问题。我不打算为这封邮件提供答案,因为我对SMTP的了解不够,无法对此感到满意。但是,这听起来确实像是一个环境问题(可能在IIS设置中)。您是否使用1)“localhost”作为smtp.Host 2)smtp.Host的远程服务器和/或3)特定IP而不是主机名?我的邮件主机是按名称引用的。例如“交换”。我已经通过ping服务器测试了DNS。这是成功的。我还测试了通过telnet到端口25的端口访问。这也是成功的。我已经在另一台机器上测试了代码,并且能够发送消息。在我看来,我需要在机器上安装某种类型的SMTP服务/协议。代码失败的计算机是Windows Vista Business。测试在Windows Server 2008 Standard上成功。请参阅:我很难找到任何确认using语句在完成时发送QUIT的内容。简而言之,如何在不使用using语句的情况下优雅地关闭连接。如果查看SmtpClient.Dispose()的文档,您将看到以下内容:“向SMTP服务器发送退出消息,优雅地结束TCP连接,并释放System.Net.Mail.SmtpClient类的当前实例使用的所有资源。”
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("me@domain.com");
//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);
}
}
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:
using(SmtpClient smtp = new SmtpClient())
{
smtp.Host = "emailservername";
smtp.Port = 25;
smtp.UseDefaultCredentials = true;
smtp.Send(mail)
}
<smtp deliveryMethod="Network">
<network host="localhost" port="25" defaultCredentials="false"/>
</smtp>
With New clsEmail(True)
With .Message
.To.Add("user@domain.com")
.Subject = msgSubject
.Body = msgContents
End With
.Server.Send(.Message)
.Server.Dispose()
.Message.Dispose()
End With