2013-05-22 86 views

回答

0

你可以使用SmtpClient類來使用Windows身份驗證發送電子郵件。 FOr只是初始化UseDefaultCredentials屬性爲true;

string to = "[email protected]"; 
string from = "[email protected]"; 
MailMessage message = new MailMessage(from, to); 
message.Subject = "Using the new SMTP client."; 
message.Body = @"Using this new feature, you can send an e-mail message from an application very easily."; 
SmtpClient client = new SmtpClient(server); 
// Credentials are necessary if the server requires the client 
// to authenticate before it will send e-mail on the client's behalf. 
client.UseDefaultCredentials = true; 

try 
{ 
    client.Send(message); 
} 
catch (Exception ex) 
{ 
    Console.WriteLine("Exception caught in CreateTestMessage2(): {0}", ex.ToString()); 
} 

這將要求您的應用程序以管理員身份運行並且有權代表指定的發件人發送電子郵件。

+0

嗨,謝謝,但我得到一個錯誤,我如何強制作爲管理員在這裏運行? –

+0

謝謝,我犯了一些錯別字。它的工作原理。 –

相關問題