请高手指定[有关邮件头的问题]----急----再线@!!!!!!!

Quentin30 2004-01-07 10:50:21
请高手指点,如何分解电子邮件头[发件人,收件人,附件...]等......
...全文
57 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Quentin30 2004-01-08
  • 打赏
  • 举报
回复
感谢谢大家的积极回答,看来我要重新发贴了。
Quentin30 2004-01-07
  • 打赏
  • 举报
回复
老大你莫豆我了,怪我没有说清楚,我想说的是:用pop3协议收到到邮件后我如何把邮件头分解开,以便显示。例如:
+OK 174655 octets
Received: from dy (unknown [218.92.199.100])
by 192.168.1.214 (Coremail) with SMTP id STUAAMRz9T8cAMdk.1
for <quzaoyu@netease.com>; Fri, 02 Jan 2004 21:36:25 +0800 (CST)
X-Originating-IP: [218.92.199.100]
Received: from online.sh.cn ([218.167.82.149]) by dy with Microsoft SMTPSVC(5.0.2172.1);
Fri, 2 Jan 2004 21:42:42 +0800
Received: from unknown (HELO ga912 [36.104.198.205])
by online.sh.cn with SMTP;
Fri, 02 Jan 2004 13:34:29 GMT
Message-Id: <1073050486-@ga912>
From: "Fu Zhou" <qian4363r561@online.sh.cn>
To: jiang8198
Subject: : µ
Sender: qian mian
MIME-Version: 1.0
Content-Type: multipart/related;
boundary="----=_NextPart_000_004A_01C3CED9.B59AEC00";
type="multipart/alternative"
Date: Fri, 2 Jan 2004 21:36:25 +0800 (CST)

This is a multi-part message in MIME format.

------=_NextPart_000_004A_01C3CED9.B59AEC00
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_004B_01C3CED9.B59AEC00"


------=_NextPart_001_004B_01C3CED9.B59AEC00
Content-Type: text/plain;
charset="gb2312"
Content-Transfer-Encoding: base64


------=_NextPart_001_004B_01C3CED9.B59AEC00
Content-Type: text/html;
charset="gb2312"
Content-Transfer-Encoding: base64

PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv
L0VOIj4NCjxIVE1MPjxIRUFEPjxUSVRMRT7QwtT2zfjSszE8L1RJVExFPjxCQVNFIGhyZWY9Zmls
ZTovL0Q6XG50ZHR2LWNoaW5hLTRcPg0KPE1FVEEgaHR0cC1lcXVpdj1Db250ZW50LUxhbmd1YWdl
....省略.
我现在要把这封邮件的邮件头分解开,什么收件人,发件人,附件......。是以什么样的关键字来定位,还是有别的好方法。还有附件怎么处理!!
bankliu 2004-01-07
  • 打赏
  • 举报
回复
一、SMTP协议简介

1、 客户端通过服务器的25端口建立TCP/IP连接

服务器端: 220 server.com Simple Mail Transfer Service Ready

2、 客户端使用“HELO”命令标识发件人

客户端:HELO server.com
服务器端:250 server.com
3、 客户端发送MAIL命令,服务器端以OK作为响应表明准备接收

客户端: MAIL FROM: <A@B.com>
服务器端: 250 OK
4、 客户端发送RCPT命令标识收件人,服务器端回应是否愿意为收件人接受邮件

客户端:RCPT TO: <d@e.com>
服务器端:250 OK
5、 协商结束后用命令DATA发送发送邮件

客户端:DATA
服务器端:354 Start mail input: end with <CRLF>.<CRLF>
6、 客户端以.表示结束输入内容一起发送出去

客户端:Subject: <CRLF>
内容<CRLF>
.<CRLF>

7、客户端用QUIT命令退出。

客户端:QUIT
服务器端:250 server.com closing transmission channel
二、SMTP客户端程序代码:

1、 用VS.NET新建一个C# WINDOWS应用程序项目,命名为SMTP。

2、 在窗体上添加控件:

一个按钮:设置属性name->btnsend;text->发送

六个标签:分别提示服务器地址、发件人、收件人、主题、内容以及发送记录

五个文本框:服务器地址txtsmtp、发件人txtfrom、收件人txtto、主题txtsub、内容txtmsg对应相应的标签放置。

一个列表框:lstlog

3、在程序开头添加以下名字空间:

using System.Data;

using System.Net;

using System.Net.Sockets;

using System.IO;

4、在 btnsend_Click 函数中添加如下代码:

点击查看
保存工程并编译,邮件发送程序就编制成功了,我们还可以进一步改造该函数,制作一个SMTP类,将其应用于自己的软件。
private void btnsend_Click(object sender, System.EventArgs e)

{

// 将鼠标形状改为漏斗状

Cursor cr = Cursor.Current;

Cursor.Current = Cursors.WaitCursor;

//定义变量

string Data;

byte[] szData;

string CRLF = "\r\n";

//创建与服务器25端口的连接

TcpClient SmtpServ = new TcpClient(txtsmtp.Text,25);

lstlog.Items.Clear();

//显示服务器初始信息

NetworkStream NetStrm = SmtpServ.GetStream();

StreamReader RdStrm= new StreamReader(SmtpServ.GetStream());

lstlog.Items.Add(RdStrm.ReadLine());

//标志发件人

Data = "HELO server " + CRLF;

szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());

NetStrm.Write(szData,0,szData.Length);

lstlog.Items.Add(RdStrm.ReadLine());

//标志发件人

Data = "MAIL FROM: " + "<" + txtfrom.Text + ">" + CRLF;

szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());

NetStrm.Write(szData,0,szData.Length);

lstlog.Items.Add(RdStrm.ReadLine(

// 标志收件人

Data = "RCPT TO: " + "<" + txtto.Text + ">" + CRLF;

szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());

NetStrm.Write(szData,0,szData.Length);

lstlog.Items.Add(RdStrm.ReadLine());

//准备发送内容

Data = "DATA " + CRLF;

szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());

NetStrm.Write(szData,0,szData.Length);

lstlog.Items.Add(RdStrm.ReadLine());

//发送主题

Data = "SUBJECT: " + txtsub.Text + CRLF ;

//发送内容

Data = Data+ txtmsg.Text + CRLF ;

//结束发送

Data = Data+ "." + CRLF;

szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());

NetStrm.Write(szData,0,szData.Length);

lstlog.Items.Add(RdStrm.ReadLine());

//退出

Data = "QUIT " + CRLF;

szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());

NetStrm.Write(szData,0,szData.Length);

lstlog.Items.Add(RdStrm.ReadLine());

//关闭连接

NetStrm.Close();

RdStrm.Close();

lstlog.Items.Add("连接关闭");

lstlog.Items.Add("发送成功");


//将鼠标恢复箭头状

Cursor.Current = cr;

}

诶~
Quentin30 2004-01-07
  • 打赏
  • 举报
回复
UP
hunter4500 2004-01-07
  • 打赏
  • 举报
回复
代替form1中代码就ok了
hunter4500 2004-01-07
  • 打赏
  • 举报
回复
//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(56, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(32, 18);
this.label1.TabIndex = 2;
this.label1.Text = "发自:";
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// ToTextBox
//
this.ToTextBox.Location = new System.Drawing.Point(123, 61);
this.ToTextBox.Name = "ToTextBox";
this.ToTextBox.Size = new System.Drawing.Size(307, 21);
this.ToTextBox.TabIndex = 1;
this.ToTextBox.Text = "";
//
// label3
//
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label3.Location = new System.Drawing.Point(56, 176);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(33, 18);
this.label3.TabIndex = 2;
this.label3.Text = "主题:";
//
// BrowseButton
//
this.BrowseButton.Location = new System.Drawing.Point(358, 213);
this.BrowseButton.Name = "BrowseButton";
this.BrowseButton.Size = new System.Drawing.Size(72, 28);
this.BrowseButton.TabIndex = 7;
this.BrowseButton.Text = "浏览...";
this.BrowseButton.Click += new System.EventHandler(this.BrowseButton_Click);
//
// SubjectTextBox
//
this.SubjectTextBox.Location = new System.Drawing.Point(123, 176);
this.SubjectTextBox.Name = "SubjectTextBox";
this.SubjectTextBox.Size = new System.Drawing.Size(307, 21);
this.SubjectTextBox.TabIndex = 4;
this.SubjectTextBox.Text = "";
//
// SendButton
//
this.SendButton.BackColor = System.Drawing.Color.Aqua;
this.SendButton.Location = new System.Drawing.Point(82, 444);
this.SendButton.Name = "SendButton";
this.SendButton.Size = new System.Drawing.Size(92, 28);
this.SendButton.TabIndex = 8;
this.SendButton.Text = "发 送";
this.SendButton.Click += new System.EventHandler(this.SendButton_Click);
//
// label2
//
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.Location = new System.Drawing.Point(56, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(40, 19);
this.label2.TabIndex = 2;
this.label2.Text = "发往:";
//
// AttachmentTextBox
//
this.AttachmentTextBox.Location = new System.Drawing.Point(123, 213);
this.AttachmentTextBox.Name = "AttachmentTextBox";
this.AttachmentTextBox.Size = new System.Drawing.Size(215, 21);
this.AttachmentTextBox.TabIndex = 5;
this.AttachmentTextBox.Text = "";
//
// FromTextBox
//
this.FromTextBox.Location = new System.Drawing.Point(123, 19);
this.FromTextBox.Name = "FromTextBox";
this.FromTextBox.Size = new System.Drawing.Size(307, 21);
this.FromTextBox.TabIndex = 0;
this.FromTextBox.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(440, 477);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.BrowseButton,
this.AttachmentTextBox,
this.label5,
this.label4,
this.BCCTextBox,
this.CCLabel,
this.CCTextBox,
this.ExitButton,
this.SendButton,
this.label3,
this.label2,
this.label1,
this.SubjectTextBox,
this.ToTextBox,
this.FromTextBox,
this.MessageTextBox});
this.Name = "Form1";
this.Text = "发送邮件";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void SendButton_Click(object sender, System.EventArgs e)
{
try
{
MailMessage aMessage = new MailMessage();
aMessage.From = FromTextBox.Text;
aMessage.To = ToTextBox.Text;
aMessage.Cc = CCTextBox.Text;
aMessage.Bcc = BCCTextBox.Text;
aMessage.Subject = SubjectTextBox.Text;
aMessage.Body = MessageTextBox.Text;
if (AttachmentTextBox.Text.Length > 0)
aMessage.Attachments.Add(new MailAttachment(AttachmentTextBox.Text, MailEncoding.Base64));

SmtpMail.Send(aMessage);

MessageBox.Show("邮件发送成功!");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}

private void ExitButton_Click(object sender, System.EventArgs e)
{
Application.Exit();
}

private void label1_Click(object sender, System.EventArgs e)
{

}

private void BrowseButton_Click(object sender, System.EventArgs e)
{
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
AttachmentTextBox.Text = this.openFileDialog1.FileName;
}
}

}
}
hunter4500 2004-01-07
  • 打赏
  • 举报
回复
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Web;
using System.Web.Mail;

namespace EMailer
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button SendButton;
private System.Windows.Forms.Button ExitButton;
private System.Windows.Forms.TextBox FromTextBox;
private System.Windows.Forms.TextBox ToTextBox;
private System.Windows.Forms.TextBox SubjectTextBox;
private System.Windows.Forms.TextBox MessageTextBox;
private System.Windows.Forms.TextBox CCTextBox;
private System.Windows.Forms.Label CCLabel;
private System.Windows.Forms.TextBox BCCTextBox;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button BrowseButton;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.TextBox AttachmentTextBox;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.CCTextBox = new System.Windows.Forms.TextBox();
this.CCLabel = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.BCCTextBox = new System.Windows.Forms.TextBox();
this.MessageTextBox = new System.Windows.Forms.TextBox();
this.ExitButton = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.ToTextBox = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.BrowseButton = new System.Windows.Forms.Button();
this.SubjectTextBox = new System.Windows.Forms.TextBox();
this.SendButton = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.AttachmentTextBox = new System.Windows.Forms.TextBox();
this.FromTextBox = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// openFileDialog1
//
this.openFileDialog1.Title = "请选择邮件附件";
//
// CCTextBox
//
this.CCTextBox.Location = new System.Drawing.Point(123, 102);
this.CCTextBox.Name = "CCTextBox";
this.CCTextBox.Size = new System.Drawing.Size(307, 21);
this.CCTextBox.TabIndex = 2;
this.CCTextBox.Text = "";
//
// CCLabel
//
this.CCLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.CCLabel.Location = new System.Drawing.Point(56, 104);
this.CCLabel.Name = "CCLabel";
this.CCLabel.Size = new System.Drawing.Size(43, 18);
this.CCLabel.TabIndex = 2;
this.CCLabel.Text = "抄送:";
//
// label4
//
this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label4.Location = new System.Drawing.Point(56, 136);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(41, 18);
this.label4.TabIndex = 2;
this.label4.Text = "密送:";
//
// label5
//
this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label5.Location = new System.Drawing.Point(56, 216);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(44, 18);
this.label5.TabIndex = 2;
this.label5.Text = "附件:";
//
// BCCTextBox
//
this.BCCTextBox.Location = new System.Drawing.Point(123, 139);
this.BCCTextBox.Name = "BCCTextBox";
this.BCCTextBox.Size = new System.Drawing.Size(307, 21);
this.BCCTextBox.TabIndex = 3;
this.BCCTextBox.Text = "";
//
// MessageTextBox
//
this.MessageTextBox.Location = new System.Drawing.Point(10, 250);
this.MessageTextBox.Multiline = true;
this.MessageTextBox.Name = "MessageTextBox";
this.MessageTextBox.Size = new System.Drawing.Size(410, 176);
this.MessageTextBox.TabIndex = 6;
this.MessageTextBox.Text = "";
//
// ExitButton
//
this.ExitButton.BackColor = System.Drawing.Color.RosyBrown;
this.ExitButton.Location = new System.Drawing.Point(256, 444);
this.ExitButton.Name = "ExitButton";
this.ExitButton.Size = new System.Drawing.Size(92, 28);
this.ExitButton.TabIndex = 9;
this.ExitButton.Text = "退 出";
this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click);

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧