会社用の Web アプリケーションを開発しています。その一部では、内部ユーザーがフォームに記入し、このユーザーに代わって電子メールを送信する必要があります。すべて社内です。古い system.net.mail と新しい microsoft.exchange.webservices の 2 つのルートを検索したところ、可能性のあるルートが見つかりましたが、交換サーバーには資格情報が必要なようです。ユーザーのログインとメールアドレス login+"@company.com" しか取得できません。どうすればこれを行うことができますか?
以下は、smtp (system.net.mail) を使用したコードですが、機能しません。
string[] username =System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split('\\');
string email = username[1] + "@company.com";
MailAddress from = new MailAddress(email);
MailAddress to = new MailAddress("someone@company.com");
MailMessage message = new MailMessage(from, to);
message.Subject = "testmail";
message.Body = "<h>testmail</h>";
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(message);