将文本发送到不同的电子邮件服务器

时间:2009-10-01 07:48:09

标签: c# .net email desktop-application

        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();

        try
        {
            MailAddress fromAddress = new MailAddress("myname@gmail.com", "Lenin");
            smtpClient.Host = "localhost";
            //smtpClient.Host = "";
            //smtpClient.Port = 25;
            message.From = fromAddress;
            message.To.Add("myname@gmail.com");
            message.Subject = "Feedback";
            //message.CC.Add("admin1@ gmail.com");
            //message.CC.Add("admin2@ gmail.com");
           // message.Bcc.Add(new MailAddress("admin3@ gmail.com"));
           // message.Bcc.Add(new MailAddress("admin4@ 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 ..etc使用Windows应用程序。 谢谢你的帮助。

2 个答案:

答案 0 :(得分:0)

SmtpClient smtpClient = new SmtpClient(host, port);

答案 1 :(得分:0)

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

尝试这个。