2

私は誰かがアカウントを設定できるウェブフォームを持っています-私は彼らに確認の電子メールを送りたいです。

私が使用しているコード:

       // Create e-mail message
        MailMessage mm = new MailMessage();
        mm.From = new MailAddress("OurOrganisationEmail@ourdomain.com", "Our Organisation");
        mm.To.Add(new MailAddress("webuser@domain.com", "Web User"));

        mm.Subject = "Confirmation";
        mm.Body = "You are now registered test";
        mm.IsBodyHtml = true;

        // Send e-mail
        sc = new SmtpClient();

        NetworkCredential basicAuthenticationInfo = new NetworkCredential(“OurOrganisationEmail@ourdomain.com”, “ourorganisationemailPassword”);
        sc.Credentials = basicAuthenticationInfo;
        sc.UseDefaultCredentials = false;

        sc.Send(mm);

web.config:

<system.net>
  <mailSettings>
    <smtp>
      <network host="mail.OurOrganisationEmail@ourdomain.com" port="9999" userName="OurOrganisationEmail@ourdomain.com" password="OurOrganisationEmailPassword"/>
    </smtp>
  </mailSettings>
</system.net>

しかし、入手してください:

System.Net.Mail.SmtpFailedRecipientException was caught
HResult=-2146233088
Message=Mailbox unavailable. The server response was: Authentication is required for relay
Source=System
FailedRecipient=<webuser@domain.com>

送信したいWebアドレスのユーザーログインの詳細が必要なようです。これを修正して、他のすべての営利企業と同じように確認メールを送信するにはどうすればよいですか?

4

3 に答える 3

5

OK - 動作しました。以下は作業中のコーディングです。NetworkCredential オブジェクトの構成が問題だったようです。私が解決策に到達するのを手伝ってくれてありがとう。

        MailAddress fromAddress =  new MailAddress("OurOrganisationEmail@ourdomain.com","Our Organisation");//"name@yourdomain.com";
        MailAddress toAddress = new MailAddress("webuser@domain.com", "Web User"); //"name@anydomain.com"; 

        //Create the MailMessage instance 
        MailMessage myMailMessage = new MailMessage(fromAddress, toAddress);

        //Assign the MailMessage's properties 
        myMailMessage.Subject = "Confirmation";
        myMailMessage.Body = "You are now registered test";
        myMailMessage.IsBodyHtml = true;

        //Create the SmtpClient object
        SmtpClient smtp = new SmtpClient();

        //Send the MailMessage (will use the Web.config settings) 
        smtp.Send(myMailMessage);

web.config

<system.net>
  <mailSettings>
    <smtp>
  <network host="mail.ourdomain.com" port="9999" userName="OurOrganisationEmail@ourdomain.com" password="OurOrganisationEmailPassword"/>
    </smtp>
  </mailSettings>
</system.net>
于 2013-02-25T15:42:08.337 に答える
1

クライアントコードは正常に見えます。問題は次の場合に発生する可能性がありますweb.config

host="mail.OurOrganisationEmail@ourdomain.com"

これemail addressは有効hostname ではなく、次のようになります。

host="mail.ourdomain.com"

動作するかどうかをテストしましたsmtp serverか?を使用していくつかの基本的なテストを行うだけtelnetです。 http://technet.microsoft.com/en-us/library/aa995718(v=exchg.65).aspx

また、追加情報については、この投稿を確認してください 。Google Appsアカウントを介してC#経由でメールを送信する

于 2013-02-25T14:21:41.620 に答える
0

これは、あなたのウェブサイトがドメイン アカウントで実行されていないためだと思います。多くのメール サーバーでは、匿名ユーザーがメールを送信することを許可していません。

ドメイン内にあるサービス アカウントを作成し、アプリケーション プールをそのサービス アカウントで実行するように設定してみてください。

于 2013-02-25T14:04:05.897 に答える