如何在不使用smtp服务器的情况下从.net应用程序自动发送电子邮件?

时间:2016-01-20 10:42:57

标签: asp.net-mvc razor

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.

这是代码

SmtpMail oMail = new SmtpMail("TryIt");
SmtpClient oSmtp = new SmtpClient();
//Set sender email address, please change it to yours
oMail.From = "yaswanthmdh@gmail.com";

//Set recipient email address, please change it to yours
oMail.To = "manojsr6@gmail.com";

//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 "gmailid@gmail.com", then the user should be the same
oServer.User = "yaswanthmdh@gmail.com";
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从应用程序发送电子邮件?

1 个答案:

答案 0 :(得分:0)

没有。这就是电子邮件的工作方式。就像您需要Web服务器来提供网页一样,您需要一个SMTP服务器来发送电子邮件。您必须与您的IT基础架构部门联系,让他们为您设置一些内容或允许您尝试使用的任何SMTP服务器。

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