2012-11-08 89 views
0

我想使用asp.net發送電子郵件,我已經配置了我的SMTP服務並添加了127.0.0.1作爲中繼。我曾經到過我家的應用程序是成功的,但我安裝在辦公室它不能發送電子郵件爲什麼?使用asp.net發送電子郵件

這裏是C#代碼

MailMessage objemail = new MailMessage(); 
objemail.To.Add(new MailAddress("[email protected]")); 
objemail.From = new MailAddress(Request.Form["inputEmail"].ToString()); 
objemail.Subject = Request.Form["inputSubject"].ToString(); 
objemail.Body = "Dari: " + Request.Form["inputName"].ToString() + "\n\n" + 
       "Phone: " + Request.Form["inputPhone"].ToString() + "\n\n" + 
       Request.Form["inputMsg"].ToString(); 
objemail.IsBodyHtml = true; 
objemail.Priority = MailPriority.Normal; 

SmtpClient objSmtpClient = new SmtpClient(); 
objSmtpClient.Send(objemail); 

這裏是web.config配置

<system.net> 
<mailSettings> 
    <smtp deliveryMethod="Network"> 
    <network host="127.0.0.1" port="25" userName="yyyy" password="xxxxx" /> 
    </smtp> 
</mailSettings> 
</system.net> 

我的辦公室使用代理,是這個問題我無法發送電子郵件?請指教

+0

它拋出什麼異常? – HackedByChinese

+0

通過在try/catch中包裝並將異常詳細信息寫入txt文件來執行一些簡單日誌記錄。否則,它可能是一堆東西。 – Hardrada

+0

沒有錯誤,但我沒有收到郵件 –

回答

-1

你可以試試這個:

objSmtpClient.EnableSsl = true 
0

可能端口號是嘗試使用的端口號"587"一些錯誤,如下圖所示:

private void SendEmail(string from, string to, string subject, string body) 
    { 
     MailMessage mail = new MailMessage(new MailAddress(from), new MailAddress(to)); 

     mail.Subject = subject; 
     mail.Body = body; 

     SmtpClient smtpMail = new SmtpClient("smtp.gmail.com"); 
     smtpMail.Port = 587; 
     smtpMail.EnableSsl = true; 
     smtpMail.Credentials = new NetworkCredential("[email protected]", "xxx"); 
     // and then send the mail 
     smtpMail.Send(mail); 
    } 
+0

我用localhost作爲郵件服務器而不是gmail –

+0

然後試試這個http://blog.divergencehosting.com/2010/01/27/testing-email-from-localhost-with-aspnet -without的SMTP服務器/ – coder