资源简介
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控件
相关资源
- 局域网文件传输 Socket编程 C#代码
- C# 异步Socket 多人聊天室完整源码
- C# winform Socket 即时通讯
- 基于GPRS的远程通讯C#程序SOCKET部分带
- vb.net通过socket实现简易多人聊天室含
- C# Winform 即时通信基于Socket
- C# .Net Socket TCP 大数据 大文件 传输 经
- C# winform实现一个服务端和多个客户端
- C# web socket 客户端实现源码
- c#串口和socket开发源码
- UDP异步通讯SocketAsyncEventArgs
- C#聊天程序
-
C#通过Socket发送ob
ject对象,序列化反 - c#IPCO多线程并发业务处理
- C# socket通信的服务器和客户端
- SharpTcpScanner扫描器1.9版
- C#基于TCP的Socket多线程通信包含服务端
- C#Socket多线程聊天室
- C#Socket 封装了Tcp/Udp传输字串、文件、
- C#.net发送邮件完整源代码DEMO完整版
- 基于C#net4.5实现最简单的websocket客户端
- C# Socket_服务端向指定的客户端发送消
- C#.net udp 点对点聊天程序
- c#源码 Socket 负载均衡
- TCP_ServerAndClient.rar
- C# Socket实现TCPClient
- C#winform TCP通信 UDP通信 Socket通信 vs2
- C# SOCKET TCP UDP测试工具及源代码
- C#Socket异步服务器 IOCP 源码
- C# 推送数据 SOCKET 完整
评论
共有 条评论