邮件发送代码
来源:互联网 发布:多宝视视觉训练软件 编辑:程序博客网 时间:2024/05/21 15:44
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
namespace 发送邮件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox8_TextChanged(object sender, EventArgs e)
{
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
OpenFileDialog OpenFileDialog = new OpenFileDialog();
openFileDialog1.InitialDirectory=Environment.GetFolderPath(Environment.SpecialFolder.Personal);
openFileDialog1.Filter = "所有文件(*.*)|*.*";
if(openFileDialog1.ShowDialog(this)==DialogResult.OK)
{
textBox3.Text=openFileDialog1.FileName;
}
}
private void button1_Click(object sender, EventArgs e)
{
string address = "";
string displayName = "";
string w_txt收件人 =textBox3.Text.Trim();
if (w_txt收件人 == "")
{
MessageBox.Show("请输入收件人地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
MailAddress from = new MailAddress(textBox5.Text, textBox7.Text); //邮件的发件人
MailMessage newMailMessage = new MailMessage();
string[] mailNames = (textBox1.Text).Split(',');
{
try
{
foreach (string name in mailNames)
{
if (name != string.Empty)
{
if (name.IndexOf('<') > 0)
{
displayName = name.Substring(0, name.IndexOf('<'));
address = name.Substring(name.IndexOf('<') + 1).Replace('>', ' ');
}
else
{
displayName = string.Empty;
address = name.Substring(name.IndexOf('<') + 1).Replace('>', ' ');
}
}
newMailMessage.From = from;
newMailMessage.To.Add(new MailAddress(address, displayName));
newMailMessage.Body = textBox4.Text;
newMailMessage.Subject = textBox2.Text;
//设置SMTP服务器地址
SmtpClient newclient = new SmtpClient("smtp.163.com");
newclient.UseDefaultCredentials = false;
//此处设置发件人邮箱的用户名和密码
newclient.Credentials = new System.Net.NetworkCredential(textBox5.Text, textBox6.Text); //发件人的账号和密码
newclient.DeliveryMethod = SmtpDeliveryMethod.Network;
newMailMessage.Attachments.Add(new Attachment(textBox3.Text)); // 发送附件
newMailMessage.Priority = MailPriority.High; //设置发送级别
//发送邮件
newclient.Send(newMailMessage);
}
MessageBox.Show("邮件发送完毕!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception exp)
{
MessageBox.Show("邮件发送发生错误:" + exp.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
toolStripProgressBar1.Visible = false;
}
}
- delphi发送邮件代码
- JMail发送邮件代码
- .net 发送邮件代码
- vs2005 邮件发送代码
- JMail发送邮件代码
- 邮件发送示例代码
- 发送邮件代码
- C#发送邮件代码
- C#邮件发送代码
- C#发送邮件代码
- 邮件发送代码
- C#邮件发送代码
- java发送邮件代码
- C#发送邮件代码
- 邮件发送代码
- C#发送邮件代码
- 发送邮件代码
- 发送邮件代码收藏
- 一.登陆,退出
- 操作系统:进程/线程同步的方式和机制,进程间通信
- ycp :public/ubuntu.img 卷名后面要加文件名
- BEGIN_MESSAGE_MAP 和END_MESSAGE_MAP() 这两个宏的具体实现与作用
- 全国八十几所重点大学ftp资源
- 邮件发送代码
- chm文件打不开解决办法综合贴(转自2A的Blog)
- 用JS判断一个html元素是否存在的五种方法
- css:浮动的理解。
- C# 中的委托和事件
- linux服务器跨网段访问设置
- javascript 判断方法是否存在
- heritrix
- sql server 自定义split(分割)函数