2009-10-01 69 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

相关问题