views:

62

answers:

2
        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("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);                
        }

please help to sent email to different server .. gmail.com/yahoo.com/inbox.com ..etc using windows application. thanks for the help.

A: 
SmtpClient smtpClient = new SmtpClient(host, port);
Robin Day
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);
A: 
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);

try this one.

Braveyard
thank you.but i would like the "client.Host" to be independent ie to using any host and sent email to anyone.
want to dynamically set the host and sent email to any email server online.thank you
Well you can assign values from an input to Host property of client instance but also you need to change network credential information, like user name and password and also port number (smtp outgoing port number) hope it helps.
Braveyard