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;
using System.ServiceProcess;namespace MailManagerSystem
{
public partial class SendForm : Form
{
//邮件附件全路径文件名
private string[] strFilePaths = new string[5];
//待发送目标邮件地址
private string[] strMailAddress;
//待发送目标邮件地址封装属性
public string[] StrMailAddress
{
get { return strMailAddress; }
set { strMailAddress = value; }
}
//构造函数
public SendForm()
{
InitializeComponent();
}
//打开文件浏览对话框事件
private void btnOpenFile_Click(object sender, EventArgs e)
{
//附件个数限制
if (lbxFile.Items.Count >=4)
{
MessageBox.Show("附件添加最大个数不能超过5。");
return;
}
//设置对话框初始属性
openFile.InitialDirectory = "C:\\";
openFile.Filter =
"All Files (*.*)|*.*|HTML Files (*.htm;*.html)|*.htm|Microsoft Mail Documents (*.msg)|*.msg|Word Documents (*.doc)|*.doc|Excel Files(*.xl*)|*.xl*|Excel Worksheets (*.xls)|*.xls|Excel Charts (*.xlc)|*.xlc|PowerPoint Presentations (*.ppt)|*.ppt|Text Files (*.txt)|*.txt";
openFile.FilterIndex = 1; //打开文件对话框
if (openFile.ShowDialog() == DialogResult.OK)
{
//记录全路径文件名
int iCount = lbxFile.Items.Count;
strFilePaths[iCount] = openFile.FileName; //获得文件名
String[] strFileName = openFile.FileName.Split('\\');
System.Array.Reverse(strFileName);
lbxFile.Items.Add(strFileName[0]);
}
}
// 发送邮件
private void btnSend_Click(object sender, EventArgs e)
{
if (tbxMailFrom.Text == "")
{
MessageBox.Show("必须输入发信邮箱地址。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (tbxMailSubject.Text == "")
{
MessageBox.Show("主题不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
} pbSendMail.Value = 0;
pbSendMail.Maximum = StrMailAddress.Length;
//打开计时器
timer.Start();
//当计时器事件中的代码执行完成后,显示提示信息
MessageBox.Show("邮件发送成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
// 计时器计数
private void timer_Tick(object sender, EventArgs e)
{
//创建新邮件
//参数分别用来初始化邮件发送和接收的地址
MailMessage mail = new MailMessage(tbxMailFrom.Text, StrMailAddress[pbSendMail.Value]);
//设置邮件主题
mail.Subject = tbxMailSubject.Text;
//设置邮件附件
for (int i = 0; i<5; i++)
{
if (strFilePaths[i] != "" && strFilePaths[i] != null)
{
mail.Attachments.Add(new Attachment(strFilePaths[i]));
}
}
//设置邮件文本
mail.Body = tbxMailText.Text; try
{
//设置SMTP服务器地址
SmtpClient client = new SmtpClient("smtp.163.com");
//发送邮件
client.Send(mail);
++pbSendMail.Value;
if (pbSendMail.Value >= pbSendMail.Maximum)
{
//邮件全部发送完毕后计时器停止
timer.Stop();
MessageBox.Show("邮件发送完毕。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception exp)
{
timer.Stop();
MessageBox.Show("邮件发送时发生以下错误:" + exp.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void groupBox1_Enter(object sender, EventArgs e)
{
} private void toolStripButton2_Click(object sender, EventArgs e)
{
this.colorDialog1.AllowFullOpen = true;
this.colorDialog1.AnyColor = true;
this.colorDialog1.FullOpen = true;
this.colorDialog1.SolidColorOnly = false;
this.colorDialog1.ShowDialog();
this.tbxMailText.ForeColor = this.colorDialog1.Color;
} private void toolStripButton1_Click(object sender, EventArgs e)
{
if (fontDialog1.ShowDialog() == DialogResult.OK)
{
this.tbxMailText.Font = this.fontDialog1.Font; }
}
}
}
出错为:邮件发送发生以下错误:不允许使用邮箱名称,服务器响应为: Authentication is required ,stmp10. Dscowlb7fqcwutpm4cfoaa--.11521s2 1278916885
各位大侠帮帮忙
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
using System.ServiceProcess;namespace MailManagerSystem
{
public partial class SendForm : Form
{
//邮件附件全路径文件名
private string[] strFilePaths = new string[5];
//待发送目标邮件地址
private string[] strMailAddress;
//待发送目标邮件地址封装属性
public string[] StrMailAddress
{
get { return strMailAddress; }
set { strMailAddress = value; }
}
//构造函数
public SendForm()
{
InitializeComponent();
}
//打开文件浏览对话框事件
private void btnOpenFile_Click(object sender, EventArgs e)
{
//附件个数限制
if (lbxFile.Items.Count >=4)
{
MessageBox.Show("附件添加最大个数不能超过5。");
return;
}
//设置对话框初始属性
openFile.InitialDirectory = "C:\\";
openFile.Filter =
"All Files (*.*)|*.*|HTML Files (*.htm;*.html)|*.htm|Microsoft Mail Documents (*.msg)|*.msg|Word Documents (*.doc)|*.doc|Excel Files(*.xl*)|*.xl*|Excel Worksheets (*.xls)|*.xls|Excel Charts (*.xlc)|*.xlc|PowerPoint Presentations (*.ppt)|*.ppt|Text Files (*.txt)|*.txt";
openFile.FilterIndex = 1; //打开文件对话框
if (openFile.ShowDialog() == DialogResult.OK)
{
//记录全路径文件名
int iCount = lbxFile.Items.Count;
strFilePaths[iCount] = openFile.FileName; //获得文件名
String[] strFileName = openFile.FileName.Split('\\');
System.Array.Reverse(strFileName);
lbxFile.Items.Add(strFileName[0]);
}
}
// 发送邮件
private void btnSend_Click(object sender, EventArgs e)
{
if (tbxMailFrom.Text == "")
{
MessageBox.Show("必须输入发信邮箱地址。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (tbxMailSubject.Text == "")
{
MessageBox.Show("主题不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
} pbSendMail.Value = 0;
pbSendMail.Maximum = StrMailAddress.Length;
//打开计时器
timer.Start();
//当计时器事件中的代码执行完成后,显示提示信息
MessageBox.Show("邮件发送成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
// 计时器计数
private void timer_Tick(object sender, EventArgs e)
{
//创建新邮件
//参数分别用来初始化邮件发送和接收的地址
MailMessage mail = new MailMessage(tbxMailFrom.Text, StrMailAddress[pbSendMail.Value]);
//设置邮件主题
mail.Subject = tbxMailSubject.Text;
//设置邮件附件
for (int i = 0; i<5; i++)
{
if (strFilePaths[i] != "" && strFilePaths[i] != null)
{
mail.Attachments.Add(new Attachment(strFilePaths[i]));
}
}
//设置邮件文本
mail.Body = tbxMailText.Text; try
{
//设置SMTP服务器地址
SmtpClient client = new SmtpClient("smtp.163.com");
//发送邮件
client.Send(mail);
++pbSendMail.Value;
if (pbSendMail.Value >= pbSendMail.Maximum)
{
//邮件全部发送完毕后计时器停止
timer.Stop();
MessageBox.Show("邮件发送完毕。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception exp)
{
timer.Stop();
MessageBox.Show("邮件发送时发生以下错误:" + exp.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private void groupBox1_Enter(object sender, EventArgs e)
{
} private void toolStripButton2_Click(object sender, EventArgs e)
{
this.colorDialog1.AllowFullOpen = true;
this.colorDialog1.AnyColor = true;
this.colorDialog1.FullOpen = true;
this.colorDialog1.SolidColorOnly = false;
this.colorDialog1.ShowDialog();
this.tbxMailText.ForeColor = this.colorDialog1.Color;
} private void toolStripButton1_Click(object sender, EventArgs e)
{
if (fontDialog1.ShowDialog() == DialogResult.OK)
{
this.tbxMailText.Font = this.fontDialog1.Font; }
}
}
}
出错为:邮件发送发生以下错误:不允许使用邮箱名称,服务器响应为: Authentication is required ,stmp10. Dscowlb7fqcwutpm4cfoaa--.11521s2 1278916885
各位大侠帮帮忙
垃圾邮件横行,现在基本上免费的邮件服务提供商都禁止了使用程序登录发送邮件的功能了。