2012-04-27 14 views
1

私はあなたのユーザーの電子メールの検証を書いてみたいです。しかし、私はいくつか問題があります。 Web.configファイルでSMTPホストが指定されていません。 InvalidOperationException

public static void SendMail(User user) 
    { 
     string verifyNewUser = "http://localhost:9928/Account/Activate/" + 
            user.Name + "/" + user.EmailKey; 
     var sr = new StreamReader("ActivateNewUser.txt"); 
     MailMessage mailMessage = new System.Net.Mail.MailMessage(); 
     mailMessage.IsBodyHtml = true; 
     mailMessage.To.Add(user.Email); 
     mailMessage.Subject = "Registration on Harb"; 
     mailMessage.Body = sr.ReadToEnd(); 
     sr.Close(); 
     mailMessage.Body = mailMessage.Body 
          .Replace("@AccountName", user.Name); 
     mailMessage.Body = mailMessage.Body 
          .Replace("@VerificationUrl", verifyNewUser); 
     var smtpClient = new SmtpClient(); 
     smtpClient.Send(mailMessage); 
    } 

は私が書く:
私はこれ持って

<system.net> 
<mailSettings> 
    <smtp deliveryMethod="Network" from="[email protected]"> 
    <network host="smtp.gmail.com" port="587" userName="[email protected]" 
     password="myPassword" defaultCredentials="false" enableSsl="true"/> 
    </smtp> 
</mailSettings> 

をしかし、私はInvalidOperationExceptionを持っています。
誰でもこの問題を解決できますか?

+0

ここで、SMTPClientサーバーを追加していますか? –

+0

私はgmailサーバーを使います。そのため、Web.configにmailSettingsを記述します。 私はあなたを正しく理解しています。 – LuckSound

答えて

0

あなたの投稿へのコメントリンクが表示されないので、ここで質問します。

例外はありますか?

関連する問題