12

C#でメールを送信しようとしています。私はさまざまな例をグーグルで検索し、それぞれから、そして誰もがおそらく使用しているであろう標準コードから断片を取り出しました。

string to = "receiver@domain.com";
string from = "sender@domain.com";
string subject = "Hello World!";
string body =  "Hello Body!";
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient("smtp.domain.com");
client.Credentials = new NetworkCredential("test@domain.com", "password");
client.Send(message);

ただし、エラーが表示され続けます

System.Net.Mail.SmtpException: メールボックスを利用できません。サーバーの応答は次のとおりでした: アクセスが拒否されました - 無効な HELO 名 (RFC2821 4.1.1.1 を参照)

それで、私は今何をしますか?SmtpClient は特別で、特定の SMTP サーバーでのみ動作するはずですか?

4

6 に答える 6

10

ユーザー名とパスワードのペアがSMTP サーバーで正常に認証されていないようです。

編集

ここで何が問題なのかがわかったと思います。以下のバージョンを修正しました。

string to = "receiver@domain.com";

//It seems, your mail server demands to use the same email-id in SENDER as with which you're authenticating. 
//string from = "sender@domain.com";
string from = "test@domain.com";

string subject = "Hello World!";
string body =  "Hello Body!";
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient("smtp.domain.com");
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("test@domain.com", "password");
client.Send(message);
于 2010-07-01T05:21:32.497 に答える
4

web.Config で認証資格情報を設定しようとしましたか?

  <system.net>
    <mailSettings>
      <smtp from="test@foo.com">
        <network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />
      </smtp>
    </mailSettings>
  </system.net>

そしてあなたのコードビハインド

MailMessage message = new MailMessage();
message.From = new MailAddress("sender@foo.bar.com");
message.To.Add(new MailAddress("recipient1@foo.bar.com"));
message.To.Add(new MailAddress("recipient2@foo.bar.com"));
message.To.Add(new MailAddress("recipient3@foo.bar.com"));
message.CC.Add(new MailAddress("carboncopy@foo.bar.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";
SmtpClient client = new SmtpClient();
client.Send(message);
于 2010-07-01T05:22:07.697 に答える
3

これを試して:

string to = "receiver@domain.com";
string from = "sender@domain.com";
string subject = "Hello World!";
string body =  "Hello Body!";
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient("smtp.domain.com");
// explicitly declare that you will be providing the credentials:
client.UseDefaultCredentials = false;
// drop the @domain stuff from your user name: (The API already knows the domain
// from the construction of the SmtpClient instance
client.Credentials = new NetworkCredential("test", "password");
client.Send(message);
于 2010-07-01T05:26:18.563 に答える