2009-10-01 67 views
-1
 SmtpClient smtpClient = new SmtpClient(); 
     MailMessage message = new MailMessage(); 

     try 
     { 
      MailAddress fromAddress = new MailAddress("[email protected]", "Lenin"); 
      smtpClient.Host = "localhost"; 
      //smtpClient.Host = ""; 
      //smtpClient.Port = 25; 
      message.From = fromAddress; 
      message.To.Add("[email protected]"); 
      message.Subject = "Feedback"; 
      //message.CC.Add("[email protected] gmail.com"); 
      //message.CC.Add("[email protected] gmail.com"); 
      // message.Bcc.Add(new MailAddress("[email protected] gmail.com")); 
      // message.Bcc.Add(new MailAddress("[email protected] gmail.com")); 
      message.IsBodyHtml = false; 
      message.Body = txtComments.Text; 
      smtpClient.Send(message); 
      MessageBox.Show("Email successfully sent."); 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show("Send Email Failed." + ex.Message);     
     } 

請幫助發送電子郵件到不同的服務器.. gmail.com/yahoo.com/inbox.com ..等使用Windows應用程序。 感謝您的幫助。發送文本到不同的電子郵件服務器

回答

0
SmtpClient smtpClient = new SmtpClient(host, port); 
+0

MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new smtpClient(「smtp.gmail.com」); userID = register.userName; password = register.pass; string aa = txtTo.Text; mail.From = new MailAddress(userID); mail.To.Add(aa); mail.Subject = txtsubject.Text; mail.Body = txtComments.Text; SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential(userID,password); SmtpServer.Send(mail); – user182323 2009-10-01 08:09:33

0
SmtpClient client = new SmtpClient(); 
client.Credentials = new System.Net.NetworkCredential("[email protected]", "password"); 
client.EnableSsl = true; 
client.Host = "smtp.gmail.com"; 
client.Port = 465 or 587; 
client.DeliveryMethod = SmtpDeliveryMethod.Network; 
client.Send(MailMessage); 

試試這個。

+0

謝謝。但我希望「client.Host」是獨立的,即使用任何主機並向任何人發送電子郵件。 – user182323 2009-10-01 08:05:41

+0

想要動態設置主機和發送到任何電子郵件服務器在線。謝謝你 – user182323 2009-10-01 08:11:37

+0

那麼你可以從輸入分配值到客戶端實例的主機屬性,但也需要更改網絡憑證信息,如用戶名和密碼,還端口號(smtp輸出端口號)希望它有幫助。 – Tarik 2009-10-01 08:25:34

相關問題