Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to send mail to various pepole listed in a textbox, when a button gets clicked in window application built in c# :omg:
Posted

protected void sendEmail(string address, string subject, string from, string body)
    {
        System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
        message.To.Add(address);
        message.Subject = subject;
        message.From = new System.Net.Mail.MailAddress(from);
        message.Body = body;
        System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
        smtp.Credentials = new System.Net.NetworkCredential("host", "password");
        smtp.Port = 587;
        smtp.Send(message);
    
    }
 
Share this answer
 
v2
Comments
RaviRanjanKr 25-Jan-11 23:27pm    
Code is wrapped in "pre" tag to make it readability
There are several articles on CodeProject that show you how to send email programatically. The rest of what you're asking is simply setting the listbox as a multi-select ListBox and iterating through the ListBox.SelectedItems collection to get the names (or email addresses, or items, whatever).
 
Share this answer
 
You need to do something like this:

// Create the email
System.Net.Mail.MailMessage mail = new MailMessage();
mail.To = "to@there.com";
mail.From = "from@here.com";
mail.Subject = "subject";
mail.Body = "the body";

// Send the email
SmtpMail.SmtpServer = "your smtp server details";
SmtpMail.Send(mail);
//Scrub that bit above, you should use system.net.mail instead.

// Send the email.
SmtpClient client = new SmtpClient("your smtp server address", portnumber);
client.Send(mail);
 
Share this answer
 
v6
i don't understand
<pre lang="xml">// Create the email
System.Net.Mail.MailMessage mail = new MailMessage();
mail.To = &quot;to@there.com&quot;;
mail.From = &quot;from@here.com&quot;;
mail.Subject = &quot;subject&quot;;
mail.Body = &quot;the body&quot;;
&lt;strike&gt;// Send the email
SmtpMail.SmtpServer = &quot;your smtp server details&quot;;
SmtpMail.Send(mail);&lt;/strike&gt;
//Scrub that bit above, you should use system.net.mail instead.
// Send the email.
SmtpClient client = new SmtpClient(&quot;your smtp server address&quot;, portnumber);
client.Send(mail);</pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900