2017-01-30 125 views
0

我尝试在ASP.net中通过SMTP发送电子邮件,但电子邮件没有发送,也没有给出任何错误。我的代码:电子邮件不在ASP.net中使用SMTP发送

   //create the mail message 
       System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); 
       //set the FROM address 
       mail.From = new MailAddress("[email protected]"); 
       //set the RECIPIENTS 
       mail.To.Add("[email protected]"); 
       //enter a SUBJECT 
       mail.Subject = "Set the subject of the mail here."; 
       //Enter the message BODY 
       mail.Body = "Enter text for the e-mail here."; 
       //set the mail server (default should be smtp.1and1.com) 
       SmtpClient smtp = new SmtpClient("smtp.1and1.com"); 
       //Enter your full e-mail address and password 
       smtp.Credentials = new NetworkCredential("[email protected]", "xxxxxxx"); 
       //send the message 
       smtp.Send(mail); 

而且我在web.config中的代码是

<system.net> 
    <mailSettings> 
     <smtp deliveryMethod="SpecifiedPickupDirectory"> 
     <specifiedPickupDirectory pickupDirectoryLocation="C:\Mail\" /> 
     </smtp> 
    </mailSettings> 
    <defaultProxy enabled="true" /> 
    </system.net> 
+0

你的smtp端口可能被阻塞或凭据可能是错误的 –

回答

0

使用断点显示每个参数的值。即使代码中没有错误,参数值也可能为空或错误。在断点之前,使用try-catch,如下所示;

   try 
       { 
        // Your codes 
       } 
       catch (Exception ex) 
       { 
        throw new Exception(ex.Message.ToString()); 
       } 
+0

我用try/catch但是没有错将被检测到。 – ajoy