悬赏分:5 该问题已到期 浏览:170 次
|
using System.Net.Mail;
MailMessage mymail = new MailMessage(); mymail.From = new MailAddress("houlei@houleixx.com"); mymail.To.Add("houleixx@163.com"); mymail.ReplyTo = new MailAddress ("houleixx@qq.com"); mymail.IsBodyHtml = true; mymail.Priority = MailPriority.Normal; mymail.Subject = "你好"; mymail.Body = "你收到了我发送的电子邮件"; //添加附件. mymail.Attachments.Add(new Attachment(this.emailfile.PostedFile.FileName.ToString())); SmtpClient sc = new SmtpClient(); sc.Host = "59.69.174.15"; sc.Send(mymail); 可以看看我的这篇文章,还有示例程序。 http://www.cnblogs.com/beniao/archive/2008/03/16/1108498.html 个人觉得博友侯垒和笨→鸟(Bird)都回答的不错,呵呵! private void btnsend_Click(object sender, System.EventArgs e) { //检查是否已指定 SMTP 服务器的 IP 地址。 //如果已指定,则撰写电子邮件 //否则显示相应的消息 if (textBox2.Text.Length >0) { //指定要用于发送电子邮件的 //SMTP 服务器 SmtpMail.SmtpServer =textBox2.Text ; //撰写电子邮件 message.From =textBox1.Text ; message.To =textBox3.Text ; message.Cc =textBox4.Text ; message.Bcc =textBox5.Text ; message.Subject =textBox6.Text ; message.Body=textBox7.Text; //如果存在附件,则将其添加到电子邮件中 message.Attachments.Clear(); for(int index=0;index<listBox1.Items.Count;index++) { MailAttachment mAttach=new MailAttachment(listBox1.Items[index].ToString()); message.Attachments.Add(mAttach); } try { //发送已撰写的电子邮件 SmtpMail.Send(message); //重置窗体 textBox1.Text=""; textBox2.Text=""; textBox3.Text=""; textBox4.Text=""; textBox5.Text=""; textBox6.Text=""; listBox1.Items.Clear(); } catch (HttpException InvFromAddr) { //如果“发件人”地址无效, //则显示相应的消息 MessageBox.Show("输入有效“发件人”电子邮件地址"+InvFromAddr.Message); return; } //直观显示电子邮件已发送 MessageBox.Show("邮件已发送"); } else { MessageBox.Show("请输入 SMTP 服务器 IP 地址"); } } |