2016-11-18 4 views
1

私はAsp.net Webアプリケーションを開発しています。私のアプリケーションでは、私はユーザーの電子メールの確認とパスワードリセット機能を設定しています。私はAsp.netを使ってアイデンティティシステムを構築しています。これらの機能は、Visual Studioに記載されているとおり、https://www.asp.net/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identityというリンクから有効にすることができます。ASP.NET Identity UserManager.SendEmailAsyncの送信者電子メール資格情報を構成する方法

しかし、それに続くために、このリンクは壊れています - https://azure.microsoft.com/en-us/gallery/store/sendgrid/sendgrid-azure/。しかし、それは大丈夫です、私はasp.netアイデンティティシステムで一つだけ知りたいです。それは電子メールを送信しています。 Visual Studioのコメント行によると、以下のようなリセットパスワードメールを送信できます。

await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); 

その行はシンプルで読みやすいです。しかし、問題はどこで送信者の電子メールの資格情報を設定できるかです。メールを送信するために使用する設定送信者のメールアドレスを変更するにはどうすればよいですか? Azureのリンクが壊れているので、私はリンクをたどることができません。これらの設定はどこで設定したり変更したりできますか?

私は、web.configファイル

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

しかし、今は電子メールを送信するには、この設定を追加してみました。

+0

これはあなたの詳細な回答ですhttps://stackoverflow.com/a/45789677/3835843 – Arif

答えて

1

最後に解決策が見つかりました。

は、私はその後、私はこの

public class EmailService : IIdentityMessageService 
    { 
     public Task SendAsync(IdentityMessage message) 
     { 
      // Plug in your email service here to send an email. 
      SmtpClient client = new SmtpClient(); 
      return client.SendMailAsync("email from web.config here", 
             message.Destination, 
             message.Subject, 
             message.Body); 

     } 
    } 

にApp_Startフォルダ内のIdentityConfig.csで

public class EmailService : IIdentityMessageService 
    { 
     public Task SendAsync(IdentityMessage message) 
     { 
      // Plug in your email service here to send an email. 

      return Task.FromResult(0); 
     } 
    } 

を更新し、この

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

のようにweb.configファイルであり、電子メールの設定を追加しました電子メールを送信すると、web.configの設定が自動的に使用されます。

+1

非同期メソッドを非同期に使用していません。 – Sinjai

関連する問題