2016-01-20 85 views
0
In my lab smtp server is blocked.I had gone through the EAsendmail package but i couldn't succeed in sending email from the application directly without using going through smtp server. 

这里是运行此代码我收到超时错误后的代码如何在不使用smtp服务器的情况下自动从.net应用程序发送电子邮件?

SmtpMail oMail = new SmtpMail("TryIt"); 
SmtpClient oSmtp = new SmtpClient(); 
//Set sender email address, please change it to yours 
oMail.From = "[email protected]"; 

//Set recipient email address, please change it to yours 
oMail.To = "[email protected]"; 

//Set email subject 
oMail.Subject = "direct email sent from c# project"; 

//Set email body 
oMail.TextBody = "this is a test email sent from c# project directly"; 

//Set SMTP server address to "". 
SmtpServer oServer = new SmtpServer("");//173.194.40.246,"74.125.237.181"); 

//Set 465 port 
oServer.Port = 465; 

//detect SSL/TLS automatically 
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto; 

//Gmail user authentication 
//For example: your email is "[email protected]", then the user should be the same 
oServer.User = "[email protected]"; 
oServer.Password = ""; 

try 
{ 
Console.WriteLine("start to send email directly ..."); 
oSmtp.SendMail(oServer, oMail); 
Console.WriteLine("email was sent successfully!"); 
} 
catch (Exception ep) 
{ 
Console.WriteLine("failed to send email with the following error:"); 
Console.WriteLine(ep.Message); 
} 

。 有没有其他方式发送电子邮件,而不是通过smtp? 有没有办法通过http发送应用程序的电子邮件?

回答

0

不,这是电子邮件的工作原理。就像您需要一个Web服务器来提供网页一样,您需要一个SMTP服务器来发送电子邮件。您必须与您的IT基础架构部门交谈,让他们为您设置一些东西或允许您尝试使用任何SMTP服务器的请求。

如果您只需测试发送电子邮件,您可以暂时使用类似Papercut的东西,然后根据您在生产环境中部署应用程序的位置和方式,它可能不再是一个问题。

+0

先生,我怀疑即使在我们的实验室smtp服务器已关闭,那么我怎么能够看到我的Gmail。 – raja

+0

那么,首先*接收*邮件工作在不同的端口和不同的协议(IMAP或POP)。其次,对于Gmail,很可能您正在网上查看它,在这种情况下,所有协议都会在Google服务器的幕后发生。你所做的只是通过端口80上的标准HTTP(S)协议发送一个接收位,这将允许非常普遍的。 –

相关问题