using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
namespace WindowsFormsApplication63
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//打开上传附件的对话框
private void btnUP_Click(object sender, EventArgs e)
{
oFDialogSFile.InitialDirectory = "C:\\";//设置对话框的初始目录为C盘
oFDialogSFile.Filter = "all files (*.*)|*.*";//筛选字符串为所有文件
oFDialogSFile.RestoreDirectory = true;
oFDialogSFile.ShowDialog();
cboxAccessories.Items.Add(oFDialogSFile.FileName.Trim());//当选择好文件后将文件名赋值给下拉框
}
//发送邮件
private void btnSend_Click(object sender, EventArgs e)
{
try
{
string file = Application.StartupPath + "testXML.xml";
//SmtpClient下的一个对象,用以设置邮件的主题和内容
System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage();
//发送端到接收端的邮箱地址
myMail = new System.Net.Mail.MailMessage(txtSEmail.Text.Trim(), txtCEmail.Text.Trim());
myMail.Subject = txtETitle.Text.Trim();
myMail.Body = txtEContent.Text.Trim();
if (cboxAccessories.Items.Count > 0)
{
for (int i = 0; i < cboxAccessories.Items.Count; i++)
{ //建立邮件附件类的一个对象,语法格式为System.Net.Mail.Attachment(文件名,文件格式)
System.Net.Mail.Attachment myAttachment = new System.Net.Mail.Attachment(
cboxAccessories.Items[i].ToString(), System.Net.Mime.MediaTypeNames.Application.Octet);
//MIME协议下的一个对象,用以设置附件的创建时间,修改时间以及读取时间
System.Net.Mime.ContentDisposition disposition = myAttachment.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
//用smtpclient对象里attachments属性,添加上面设置好的myattachment
myMail.Attachments.Add(myAttachment);
}
}
//建立发送对象client,验证邮件服务器,服务器端口,用户名,以及密码
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(txtSService.Text.Trim(), Convert.ToInt32(txtServicePort.Text.Trim()));
client.Credentials = new System.Net.NetworkCredential(txtUPwd.Text.Trim(), txtCEmail.Text.Trim());
client.Send(myMail);
MessageBox.Show("邮件发送成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void 删除上传文件_Click(object sender, EventArgs e)
{
if (cboxAccessories.Text == "")
{
MessageBox.Show("没有附件可删!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
cboxAccessories.Items.Remove(cboxAccessories.Text.Trim());
}
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有