资源简介
C# 基于SMTP协议和SOCKET发送邮件及附件。
在WIN7的VS2010环境下编译测试OK。
代码片段和文件信息
using System;
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.Sockets;
using UtilSp.ClassLib;
using System.Threading;
using System.Linq.expressions;
namespace SmtpTest
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
private Helper helper_ = new Helper();
private void buttonSend_Click(object sender EventArgs e)
{
SmtpSp smtpSp = new SmtpSp();
SmtpSp.MailInfo mailInfo = new SmtpSp.MailInfo();
mailInfo.senderAddress_pro = textBoxSender.Text;
mailInfo.receiverAddresses_pro = new List(textBoxReceivers.Text.Split(‘;‘));
mailInfo.subject_pro = textBoxSubject.Text;
mailInfo.content_pro = textBoxContent.Text;
mailInfo.userName_pro = textBoxUserName.Text;
mailInfo.password_pro = textBoxPassword.Text;
if (listBoxAttachment.Items.Count > 0)
{
string[] attachments = new string[listBoxAttachment.Items.Count];
listBoxAttachment.Items.CopyTo(attachments 0);
mailInfo.attachments_pro = new List(attachments);
}
helper_.statusInfo_pro = “Sending...“;
this.Refresh();
Thread sendThread = new Thread(() =>
{
bool isSendOK = smtpSp.send(textBoxServer.Text 25 mailInfo);
string sendResult = ““;
if (isSendOK)
{
sendResult = “Send ok“;
}
else
{
string failMessage = “Send Fail!“;
if (smtpSp.exception_pro != null)
{
failMessage += smtpSp.exception_pro.Message;
}
sendResult = failMessage;
}
this.Invoke((Action)(() => {
helper_.statusInfo_pro =sendResult;
}));
});
sendThread.IsBackground = true;
sendThread.Start();
}
private void FormMain_Load(object sender EventArgs e)
{
buttonStatus.DataBindings.Add(“Text“ helper_ “statusInfo_pro“);
}
private void listBoxAttachment_MouseDown(object sender MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
contextMenuStripAttachment.Show(sender as Control e.X e.Y);
}
}
private void addToolStripMenuItem_Click(object sender EventArgs e)
{
string attachmentPath = FileSp.getOpenDialogFileName();
if (string.IsNullOrEmpty(attachmentPath))
{
- 上一篇:单纯形法源程序(C#)
- 下一篇:C# 透明 背景 的垂直 Label控件
相关资源
- C# Socket Server Client 通讯应用 完整的服
- C# Socket Tcp文件传输和文字聊天系统
- 用WPF开发的多人聊天室 语言C#
- C# Socket TCP通信
- unity+Socket+KCP+Protobuf的Unity局域网联机
- NET CORE 下实现WEB SOCKET通信
- 使用Socket发送数据
- SignalR在线聊天(websocket)
- Socket获取扫码枪扫码的数据
- Socket聊天室(客户端与服务端相互通
- socket服务端
- socket通讯实例(入门级)58873
- C#多线程以及Socket通讯
- 大文件Socket 传输 客户端和服务端
- Tcp/ip socket 服务器/客户端
- C#发送邮件(支持多个收件人/支持抄
- Sockets通信框架
- C# winform Socket大文件传输
- C# 实现局域网视频监控Socket 编程
- C# 使用 TcpClient,Socket 聊天
- 网页js与本地C#程序 websocket通讯实现打
- 使用WPF+MVVMlight编写的Socket服务器/多客
- winform五子棋联机版
- vb.net 与 c#.net 网络编程之 socket 套接字
- C#高性能大容量SOCKET并发
- 基于.NET/C#平台socket技术开发的一个多
- C# .NET Web API 完整 Demo
- C#超级通信调试工具源码可直接运行
- winform客户端SuperWebSocket通信Demo
- 基于Socket的企业聊天软件源码201267
评论
共有 条评论