2016-01-20 68 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)協議發送一個接收位,這將允許非常普遍的。 –

相關問題