778 lines
25 KiB
C#
778 lines
25 KiB
C#
using System;
|
||
using System.Drawing;
|
||
using System.Collections;
|
||
using System.ComponentModel;
|
||
using System.Windows.Forms;
|
||
using System.Net ;
|
||
using System.Net .Sockets ;
|
||
using MailSend;
|
||
using System.Data ;
|
||
using System.Runtime .InteropServices ;
|
||
namespace MailManageSystem
|
||
{
|
||
/// <summary>
|
||
/// Send µÄժҪ˵Ã÷¡£
|
||
/// </summary>
|
||
public class SendMailForm : System.Windows.Forms.Form
|
||
{
|
||
private System.Windows.Forms.MainMenu mainMenu1;
|
||
private System.Windows.Forms.MenuItem menuItem1;
|
||
private System.Windows.Forms.MenuItem menuItem2;
|
||
private System.Windows.Forms.MenuItem menuItem3;
|
||
private System.Windows.Forms.MenuItem menuItem4;
|
||
private System.Windows.Forms.MenuItem menuItem5;
|
||
private System.Windows.Forms.MenuItem menuItem6;
|
||
private System.Windows.Forms.MenuItem menuItem7;
|
||
private System.Windows.Forms.MenuItem menuItem8;
|
||
private System.ComponentModel.IContainer components;
|
||
private System.Windows.Forms.OpenFileDialog openFileDialog1;//ÓïÑÔ±àÂë
|
||
|
||
private System.Windows.Forms.ToolBar toolBar1;
|
||
private System.Windows.Forms.ToolBarButton tbSend;
|
||
private System.Windows.Forms.ToolBarButton tbSave;
|
||
private System.Windows.Forms.ToolBarButton toolBarButton1;
|
||
private System.Windows.Forms.ToolBarButton tbAttachment;
|
||
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
|
||
private System.Windows.Forms.ImageList imlSendMail;
|
||
private System.Windows.Forms.ImageList imlAttachment;
|
||
private System.Windows.Forms.ContextMenu conAttachment;
|
||
private System.Windows.Forms.MenuItem menuItem9;
|
||
private System.Windows.Forms.MenuItem menuItem10;
|
||
private System.Windows.Forms.MenuItem menuItem11;
|
||
private System.Windows.Forms.MenuItem menuItem12;
|
||
private System.Windows.Forms.MenuItem menuItem13;
|
||
private System.Windows.Forms.MenuItem menuItem14;
|
||
private System.Windows.Forms.MenuItem menuItem15;
|
||
private System.Windows.Forms.MenuItem menuItem16;
|
||
private System.Windows.Forms.MenuItem menuItem17;
|
||
private System.Windows.Forms.GroupBox groupBox2;
|
||
private System.Windows.Forms.TextBox txtTo;
|
||
private System.Windows.Forms.Label label3;
|
||
private System.Windows.Forms.Label label4;
|
||
private System.Windows.Forms.TextBox txtSubject;
|
||
private System.Windows.Forms.Splitter splitter1;
|
||
private System.Windows.Forms.Panel panel1;
|
||
private System.Windows.Forms.RichTextBox txtMessage;
|
||
private ArrayList array=new ArrayList ();
|
||
private System.Windows.Forms.ListView ltAttachment;
|
||
private System.Windows.Forms.ComboBox cbHtml;
|
||
|
||
int i = 0;
|
||
|
||
//EntryPoint ¸ø³öDllÈë¿ÚµãµÄÃû³Æ£¬Èç¹ûûÓиø³ö£¬ÔòÓ÷½·¨±¾ÉíµÄÃû³Æ¡£
|
||
[DllImport("shell32.dll",EntryPoint="ShellExecute")]
|
||
|
||
private static extern int ShellExecute(IntPtr hwnd, string lpOperation,string lpFile, string lpParameters, string lpDirectory, int nShowCmd);
|
||
|
||
|
||
|
||
//º¯ÊýSHGetFileInfo()µÄ·µ»ØÖµÒ²ËæuFlagsµÄÈ¡Öµ±ä»¯¶øÓÐËù²»Í¬¡£
|
||
//ͨ¹ýµ÷ÓÃSHGetFileInfo()¿ÉÒÔÓÉpsfi²ÎÊýµÃµ½ÎļþµÄͼ±ê¾ä±ú£¬µ«Òª×¢ÒâÔÚuFlags²ÎÊýÖв»Ê¹ÓÃSHGFI_PIDLʱ£¬SHGetFileInfo()²»ÄÜ»ñµÃ"ÎҵĵçÄÔ"µÈÐéËÆÎļþ¼ÐµÄÐÅÏ¢¡£
|
||
|
||
[DllImport("Shell32.dll")]
|
||
private static extern int SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, SHGFI uFlags);
|
||
|
||
|
||
[StructLayout(LayoutKind.Sequential)]
|
||
private struct SHFILEINFO
|
||
{
|
||
//ÖØÔØÒ»¸ö¹¹Ô캯Êý
|
||
public SHFILEINFO(bool b)
|
||
{
|
||
hIcon = IntPtr.Zero ; iIcon = 0; dwAttributes = 0; szDisplayName = ""; szTypeName = "";
|
||
}
|
||
public IntPtr hIcon;
|
||
public int iIcon;
|
||
public uint dwAttributes;
|
||
[MarshalAs(UnmanagedType.LPStr, SizeConst =256)]
|
||
public string szDisplayName;
|
||
[MarshalAs(UnmanagedType.LPStr, SizeConst = 80)]
|
||
public string szTypeName;
|
||
};
|
||
|
||
//ͼ±êÀàÐ͵ĽṹÌå
|
||
private enum SHGFI
|
||
{
|
||
SHGFI_ICON =0x000000100, // get icon
|
||
SHGFI_DISPLAYNAME =0x000000200, // get display name
|
||
SHGFI_TYPENAME =0x000000400, // get type name
|
||
SHGFI_ATTRIBUTES =0x000000800, // get attributes
|
||
SHGFI_ICONLOCATION =0x000001000, // get icon location
|
||
SHGFI_EXETYPE =0x000002000, // return exe type
|
||
SHGFI_SYSICONINDEX =0x000004000, // get system icon index
|
||
SHGFI_LINKOVERLAY =0x000008000, // put a link overlay on icon
|
||
SHGFI_SELECTED =0x000010000, // show icon in selected state
|
||
SHGFI_ATTR_SPECIFIED =0x000020000, // get only specified attributes
|
||
SHGFI_LARGEICON =0x000000000, // get large icon
|
||
SHGFI_SMALLICON =0x000000001, // get small icon
|
||
SHGFI_OPENICON =0x000000002, // get open icon
|
||
SHGFI_SHELLICONSIZE =0x000000004, // get shell size icon
|
||
SHGFI_PIDL =0x000000008, // pszPath is a pidl
|
||
SHGFI_USEFILEATTRIBUTES =0x000000010, // use passed dwFileAttribute
|
||
SHGFI_ADDOVERLAYS =0x000000020, // apply the appropriate overlays
|
||
SHGFI_OVERLAYINDEX =0x000000040 // Get the index of the overlay
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// µ÷ÓûñµÄ³ÌÐòͼ±ê¾ä±úµÄº¯Êý
|
||
/// </summary>
|
||
/// <param name="strPath">Ñ¡¶¨³ÌÐòµÄ¾ø¶Ô·¾¶</param>
|
||
/// <returns></returns>
|
||
|
||
private static Icon GetIcon(string strPath)
|
||
{
|
||
try
|
||
{
|
||
SHFILEINFO info = new SHFILEINFO();
|
||
int cbFileInfo = Marshal.SizeOf(info);
|
||
SHGFI flags;
|
||
|
||
flags = SHGFI.SHGFI_ICON|SHGFI.SHGFI_LARGEICON|SHGFI.SHGFI_ATTRIBUTES|SHGFI.SHGFI_EXETYPE;
|
||
|
||
SHGetFileInfo(strPath, 32|0, ref info,(uint)cbFileInfo,flags);
|
||
return Icon.FromHandle(info.hIcon);
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
MessageBox.Show (ex.ToString ());
|
||
return null;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
public SendMailForm()
|
||
{
|
||
//
|
||
// Windows ´°ÌåÉè¼ÆÆ÷Ö§³ÖËù±ØÐèµÄ
|
||
//
|
||
|
||
InitializeComponent();
|
||
|
||
//
|
||
// TODO: ÔÚ InitializeComponent µ÷ÓúóÌí¼ÓÈκι¹Ô캯Êý´úÂë
|
||
//
|
||
}
|
||
|
||
/// <summary>
|
||
/// ÇåÀíËùÓÐÕýÔÚʹÓõÄ×ÊÔ´¡£
|
||
/// </summary>
|
||
protected override void Dispose( bool disposing )
|
||
{
|
||
if( disposing )
|
||
{
|
||
if(components != null)
|
||
{
|
||
components.Dispose();
|
||
}
|
||
}
|
||
base.Dispose( disposing );
|
||
}
|
||
|
||
#region Windows ´°ÌåÉè¼ÆÆ÷Éú³ÉµÄ´úÂë
|
||
/// <summary>
|
||
/// Éè¼ÆÆ÷Ö§³ÖËùÐèµÄ·½·¨ - ²»ÒªÊ¹ÓôúÂë±à¼Æ÷ÐÞ¸Ä
|
||
/// ´Ë·½·¨µÄÄÚÈÝ¡£
|
||
/// </summary>
|
||
private void InitializeComponent()
|
||
{
|
||
this.components = new System.ComponentModel.Container();
|
||
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(SendMailForm));
|
||
this.mainMenu1 = new System.Windows.Forms.MainMenu();
|
||
this.menuItem1 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem2 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem3 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem8 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem4 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem5 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem6 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem7 = new System.Windows.Forms.MenuItem();
|
||
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
|
||
this.toolBar1 = new System.Windows.Forms.ToolBar();
|
||
this.tbSend = new System.Windows.Forms.ToolBarButton();
|
||
this.tbSave = new System.Windows.Forms.ToolBarButton();
|
||
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
|
||
this.tbAttachment = new System.Windows.Forms.ToolBarButton();
|
||
this.imlSendMail = new System.Windows.Forms.ImageList(this.components);
|
||
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
|
||
this.imlAttachment = new System.Windows.Forms.ImageList(this.components);
|
||
this.conAttachment = new System.Windows.Forms.ContextMenu();
|
||
this.menuItem9 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem10 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem11 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem12 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem13 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem14 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem15 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem17 = new System.Windows.Forms.MenuItem();
|
||
this.menuItem16 = new System.Windows.Forms.MenuItem();
|
||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||
this.cbHtml = new System.Windows.Forms.ComboBox();
|
||
this.txtTo = new System.Windows.Forms.TextBox();
|
||
this.label3 = new System.Windows.Forms.Label();
|
||
this.label4 = new System.Windows.Forms.Label();
|
||
this.txtSubject = new System.Windows.Forms.TextBox();
|
||
this.ltAttachment = new System.Windows.Forms.ListView();
|
||
this.splitter1 = new System.Windows.Forms.Splitter();
|
||
this.panel1 = new System.Windows.Forms.Panel();
|
||
this.txtMessage = new System.Windows.Forms.RichTextBox();
|
||
this.groupBox2.SuspendLayout();
|
||
this.panel1.SuspendLayout();
|
||
this.SuspendLayout();
|
||
//
|
||
// mainMenu1
|
||
//
|
||
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
||
this.menuItem1,
|
||
this.menuItem5,
|
||
this.menuItem6});
|
||
//
|
||
// menuItem1
|
||
//
|
||
this.menuItem1.Index = 0;
|
||
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
||
this.menuItem2,
|
||
this.menuItem3,
|
||
this.menuItem8,
|
||
this.menuItem4});
|
||
this.menuItem1.Text = "Óʼþ(M)";
|
||
//
|
||
// menuItem2
|
||
//
|
||
this.menuItem2.Index = 0;
|
||
this.menuItem2.Text = "Á¢¼´·¢ËÍ";
|
||
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
|
||
//
|
||
// menuItem3
|
||
//
|
||
this.menuItem3.Index = 1;
|
||
this.menuItem3.Text = "²Ý¸å";
|
||
//
|
||
// menuItem8
|
||
//
|
||
this.menuItem8.Index = 2;
|
||
this.menuItem8.Text = "-";
|
||
//
|
||
// menuItem4
|
||
//
|
||
this.menuItem4.Index = 3;
|
||
this.menuItem4.Text = "Í˳ö";
|
||
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
|
||
//
|
||
// menuItem5
|
||
//
|
||
this.menuItem5.Index = 1;
|
||
this.menuItem5.Text = "";
|
||
//
|
||
// menuItem6
|
||
//
|
||
this.menuItem6.Index = 2;
|
||
this.menuItem6.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
||
this.menuItem7});
|
||
this.menuItem6.Text = "²åÈë(I)";
|
||
//
|
||
// menuItem7
|
||
//
|
||
this.menuItem7.Index = 0;
|
||
this.menuItem7.Text = "Ôö¼Ó¸½¼þ";
|
||
this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
|
||
//
|
||
// toolBar1
|
||
//
|
||
this.toolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
|
||
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
|
||
this.tbSend,
|
||
this.tbSave,
|
||
this.toolBarButton1,
|
||
this.tbAttachment});
|
||
this.toolBar1.ButtonSize = new System.Drawing.Size(100, 80);
|
||
this.toolBar1.DropDownArrows = true;
|
||
this.toolBar1.Font = new System.Drawing.Font("ËÎÌå", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
|
||
this.toolBar1.ImageList = this.imlSendMail;
|
||
this.toolBar1.Location = new System.Drawing.Point(0, 0);
|
||
this.toolBar1.Name = "toolBar1";
|
||
this.toolBar1.ShowToolTips = true;
|
||
this.toolBar1.Size = new System.Drawing.Size(800, 41);
|
||
this.toolBar1.TabIndex = 3;
|
||
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
|
||
//
|
||
// tbSend
|
||
//
|
||
this.tbSend.ImageIndex = 0;
|
||
this.tbSend.Text = "·¢ËÍ";
|
||
//
|
||
// tbSave
|
||
//
|
||
this.tbSave.ImageIndex = 1;
|
||
this.tbSave.Text = "±£´æ";
|
||
//
|
||
// toolBarButton1
|
||
//
|
||
this.toolBarButton1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
|
||
//
|
||
// tbAttachment
|
||
//
|
||
this.tbAttachment.ImageIndex = 2;
|
||
this.tbAttachment.Text = "¸½¼þ";
|
||
//
|
||
// imlSendMail
|
||
//
|
||
this.imlSendMail.ImageSize = new System.Drawing.Size(16, 16);
|
||
this.imlSendMail.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imlSendMail.ImageStream")));
|
||
this.imlSendMail.TransparentColor = System.Drawing.Color.Transparent;
|
||
//
|
||
// imlAttachment
|
||
//
|
||
this.imlAttachment.ImageSize = new System.Drawing.Size(16, 16);
|
||
this.imlAttachment.TransparentColor = System.Drawing.Color.Transparent;
|
||
//
|
||
// conAttachment
|
||
//
|
||
this.conAttachment.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
||
this.menuItem9,
|
||
this.menuItem10,
|
||
this.menuItem11,
|
||
this.menuItem12,
|
||
this.menuItem13,
|
||
this.menuItem14});
|
||
//
|
||
// menuItem9
|
||
//
|
||
this.menuItem9.Index = 0;
|
||
this.menuItem9.Shortcut = System.Windows.Forms.Shortcut.Alt0;
|
||
this.menuItem9.Text = "Ôö¼Ó(A)...";
|
||
this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click_1);
|
||
//
|
||
// menuItem10
|
||
//
|
||
this.menuItem10.Index = 1;
|
||
this.menuItem10.Shortcut = System.Windows.Forms.Shortcut.Alt1;
|
||
this.menuItem10.Text = "ɾ³ý(D)...";
|
||
this.menuItem10.Click += new System.EventHandler(this.menuItem10_Click);
|
||
//
|
||
// menuItem11
|
||
//
|
||
this.menuItem11.Index = 2;
|
||
this.menuItem11.Text = "-";
|
||
//
|
||
// menuItem12
|
||
//
|
||
this.menuItem12.Index = 3;
|
||
this.menuItem12.Shortcut = System.Windows.Forms.Shortcut.Alt2;
|
||
this.menuItem12.Text = "´ò¿ª(O)...";
|
||
this.menuItem12.Click += new System.EventHandler(this.menuItem12_Click);
|
||
//
|
||
// menuItem13
|
||
//
|
||
this.menuItem13.Index = 4;
|
||
this.menuItem13.Text = "-";
|
||
//
|
||
// menuItem14
|
||
//
|
||
this.menuItem14.Index = 5;
|
||
this.menuItem14.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
||
this.menuItem15,
|
||
this.menuItem17,
|
||
this.menuItem16});
|
||
this.menuItem14.Text = "ÅÅÁÐͼ±ê(V)...";
|
||
//
|
||
// menuItem15
|
||
//
|
||
this.menuItem15.Index = 0;
|
||
this.menuItem15.Text = "´óͼ±ê";
|
||
this.menuItem15.Click += new System.EventHandler(this.menuItem15_Click_1);
|
||
//
|
||
// menuItem17
|
||
//
|
||
this.menuItem17.Index = 1;
|
||
this.menuItem17.Text = "Сͼ±ê";
|
||
this.menuItem17.Click += new System.EventHandler(this.menuItem17_Click);
|
||
//
|
||
// menuItem16
|
||
//
|
||
this.menuItem16.Index = 2;
|
||
this.menuItem16.Text = "Áбí";
|
||
this.menuItem16.Click += new System.EventHandler(this.menuItem16_Click_1);
|
||
//
|
||
// groupBox2
|
||
//
|
||
this.groupBox2.Controls.Add(this.cbHtml);
|
||
this.groupBox2.Controls.Add(this.txtTo);
|
||
this.groupBox2.Controls.Add(this.label3);
|
||
this.groupBox2.Controls.Add(this.label4);
|
||
this.groupBox2.Controls.Add(this.txtSubject);
|
||
this.groupBox2.Dock = System.Windows.Forms.DockStyle.Top;
|
||
this.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
||
this.groupBox2.Location = new System.Drawing.Point(0, 41);
|
||
this.groupBox2.Name = "groupBox2";
|
||
this.groupBox2.Size = new System.Drawing.Size(800, 104);
|
||
this.groupBox2.TabIndex = 4;
|
||
this.groupBox2.TabStop = false;
|
||
this.groupBox2.Text = "ÓʼþÍ·";
|
||
//
|
||
// cbHtml
|
||
//
|
||
this.cbHtml.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||
this.cbHtml.Items.AddRange(new object[] {
|
||
"HTMLÓʼþ",
|
||
"´¿Îı¾Óʼþ"});
|
||
this.cbHtml.Location = new System.Drawing.Point(704, 72);
|
||
this.cbHtml.Name = "cbHtml";
|
||
this.cbHtml.Size = new System.Drawing.Size(88, 20);
|
||
this.cbHtml.TabIndex = 8;
|
||
this.cbHtml.Text = "HTMLÓʼþ";
|
||
//
|
||
// txtTo
|
||
//
|
||
this.txtTo.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||
| System.Windows.Forms.AnchorStyles.Left)
|
||
| System.Windows.Forms.AnchorStyles.Right)));
|
||
this.txtTo.Location = new System.Drawing.Point(88, 72);
|
||
this.txtTo.Name = "txtTo";
|
||
this.txtTo.Size = new System.Drawing.Size(584, 21);
|
||
this.txtTo.TabIndex = 6;
|
||
this.txtTo.Text = "yinhu82@163.com,yinhu82@sina.com.cn";
|
||
//
|
||
// label3
|
||
//
|
||
this.label3.Location = new System.Drawing.Point(24, 72);
|
||
this.label3.Name = "label3";
|
||
this.label3.Size = new System.Drawing.Size(48, 23);
|
||
this.label3.TabIndex = 5;
|
||
this.label3.Text = "ÊÕ¼þÈË:";
|
||
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||
//
|
||
// label4
|
||
//
|
||
this.label4.Location = new System.Drawing.Point(16, 32);
|
||
this.label4.Name = "label4";
|
||
this.label4.Size = new System.Drawing.Size(64, 23);
|
||
this.label4.TabIndex = 4;
|
||
this.label4.Text = "ÓʼþÖ÷Ìâ:";
|
||
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||
//
|
||
// txtSubject
|
||
//
|
||
this.txtSubject.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||
| System.Windows.Forms.AnchorStyles.Left)
|
||
| System.Windows.Forms.AnchorStyles.Right)));
|
||
this.txtSubject.Location = new System.Drawing.Point(88, 32);
|
||
this.txtSubject.Name = "txtSubject";
|
||
this.txtSubject.Size = new System.Drawing.Size(664, 21);
|
||
this.txtSubject.TabIndex = 7;
|
||
this.txtSubject.Text = "×îаæ";
|
||
//
|
||
// ltAttachment
|
||
//
|
||
this.ltAttachment.AllowDrop = true;
|
||
this.ltAttachment.ContextMenu = this.conAttachment;
|
||
this.ltAttachment.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||
this.ltAttachment.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
|
||
this.ltAttachment.LargeImageList = this.imlAttachment;
|
||
this.ltAttachment.Location = new System.Drawing.Point(0, 392);
|
||
this.ltAttachment.Name = "ltAttachment";
|
||
this.ltAttachment.Size = new System.Drawing.Size(800, 97);
|
||
this.ltAttachment.TabIndex = 5;
|
||
this.ltAttachment.DragDrop += new System.Windows.Forms.DragEventHandler(this.listView1_DragDrop);
|
||
this.ltAttachment.DragEnter += new System.Windows.Forms.DragEventHandler(this.listView1_DragEnter);
|
||
//
|
||
// splitter1
|
||
//
|
||
this.splitter1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
|
||
this.splitter1.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||
this.splitter1.Location = new System.Drawing.Point(0, 388);
|
||
this.splitter1.Name = "splitter1";
|
||
this.splitter1.Size = new System.Drawing.Size(800, 4);
|
||
this.splitter1.TabIndex = 6;
|
||
this.splitter1.TabStop = false;
|
||
//
|
||
// panel1
|
||
//
|
||
this.panel1.Controls.Add(this.txtMessage);
|
||
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||
this.panel1.Location = new System.Drawing.Point(0, 145);
|
||
this.panel1.Name = "panel1";
|
||
this.panel1.Size = new System.Drawing.Size(800, 243);
|
||
this.panel1.TabIndex = 7;
|
||
//
|
||
// txtMessage
|
||
//
|
||
this.txtMessage.Dock = System.Windows.Forms.DockStyle.Fill;
|
||
this.txtMessage.Location = new System.Drawing.Point(0, 0);
|
||
this.txtMessage.Name = "txtMessage";
|
||
this.txtMessage.Size = new System.Drawing.Size(800, 243);
|
||
this.txtMessage.TabIndex = 0;
|
||
this.txtMessage.Text = "ºÇºÇ ÕâÊǵÚÒ»·âÊÔÑéÓʼþ";
|
||
//
|
||
// SendMailForm
|
||
//
|
||
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
|
||
this.ClientSize = new System.Drawing.Size(800, 489);
|
||
this.Controls.Add(this.panel1);
|
||
this.Controls.Add(this.splitter1);
|
||
this.Controls.Add(this.ltAttachment);
|
||
this.Controls.Add(this.groupBox2);
|
||
this.Controls.Add(this.toolBar1);
|
||
this.Menu = this.mainMenu1;
|
||
this.Name = "SendMailForm";
|
||
this.Text = "Send";
|
||
this.Load += new System.EventHandler(this.SendMailForm_Load);
|
||
this.groupBox2.ResumeLayout(false);
|
||
this.panel1.ResumeLayout(false);
|
||
this.ResumeLayout(false);
|
||
|
||
}
|
||
#endregion
|
||
|
||
|
||
//·¢ËÍÓʼþ
|
||
private void menuItem2_Click(object sender, System.EventArgs e)
|
||
{
|
||
bool html=false;
|
||
if(this.cbHtml .Text=="HTMLÓʼþ"|this.cbHtml .Text =="´¿Îı¾Óʼþ")
|
||
{
|
||
if(this.cbHtml .Text=="HTMLÓʼþ")
|
||
html=true;
|
||
else if(this.cbHtml .Text=="´¿Îı¾Óʼþ")
|
||
html=false;
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show ("Çë×ö³öÓÐЧµÄÓʼþ¸ñʽѡÔñ");
|
||
this.cbHtml .Text ="HTMLÓʼþ";
|
||
return;
|
||
}
|
||
|
||
SmtpMail send=new SmtpMail (array);
|
||
Cursor.Current =Cursors.WaitCursor ;
|
||
send.Charset ="GB2312";
|
||
send.Priority ="Normal";
|
||
send.eSmtp=true;
|
||
send.MailServerUserName =SystemManage.UserName ;
|
||
send.MailServerPassWord =SystemManage.PassWd ;
|
||
send.Send (SystemManage.SmtpName,SystemManage.MailAddress ,SystemManage.AccountName,this.txtTo .Text ,html,this.txtSubject .Text ,this.txtMessage .Text );
|
||
Cursor.Current =Cursors.Default ;
|
||
SystemManage.letterNumber ++;
|
||
ltAttachment .Items .Clear ();
|
||
this.Close ();
|
||
}
|
||
|
||
|
||
|
||
private void menuItem4_Click(object sender, System.EventArgs e)
|
||
{
|
||
this.Close ();
|
||
}
|
||
|
||
//Ìí¼Ó¸½¼þÃû³ÆºÍͼ±êµÄº¯Êý
|
||
private void btnAdd_Click()
|
||
{
|
||
|
||
if(this.openFileDialog1 .ShowDialog()==DialogResult.OK)
|
||
{
|
||
array.Add (this.openFileDialog1 .FileName );
|
||
AddIcon(this.openFileDialog1.FileName);
|
||
ltAttachment .Visible =true;
|
||
this.splitter1 .Visible =true;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// ÅжϼÓÈëµÄÎļþ¸ñʽ£¬²¢Ìí¼Óµ½¸½¼þListViewÖÐ
|
||
/// </summary>
|
||
/// <param name="fileType"></param>
|
||
private void AddIcon(string fileType)
|
||
{
|
||
//string type = fileType.Substring(fileType.Length - 3);
|
||
try
|
||
{
|
||
string Name = fileType.Substring(fileType.LastIndexOf(@"\") + 1);
|
||
this.imlAttachment.Images.Add(GetIcon(fileType));
|
||
this.ltAttachment.LargeImageList = this.imlAttachment;
|
||
this.ltAttachment .SmallImageList =this.imlAttachment ;
|
||
this.ltAttachment .Items .Add (Name,i++);
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
MessageBox.Show(ex.ToString ());
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
|
||
{
|
||
switch(this.toolBar1 .Buttons.IndexOf (e.Button ))
|
||
{
|
||
case 0:
|
||
menuItem2_Click(null,null);
|
||
break;
|
||
case 1:
|
||
this.saveFileDialog1.Title ="±£´æÐżþ";
|
||
this.saveFileDialog1 .Filter ="Îı¾Îļþ(*.txt)|*.txt|All Files(*.*)|*.*";
|
||
AddExtra extra=new AddExtra( array);
|
||
string info="SMTPµØÖ·:"+SystemManage.SmtpName+"\r\nÓû§Ãû:"+SystemManage.UserName+"\r\nÃÜÂë:"+SystemManage.PassWd+"\r\n·¢ÐÅÈ˵ØÖ·:"+SystemManage.MailAddress+"\r\nÖ÷Ìâ:"+this.txtSubject .Text+"\r\nÊÕÐÅÈ˵ØÖ·:"+this.txtTo .Text +"\r\nÐżþÄÚÈÝ:"+this.txtMessage .Text+"\r\n";
|
||
if(this.saveFileDialog1 .ShowDialog ()==DialogResult.OK )
|
||
{
|
||
extra.SaveLetter (this.saveFileDialog1 .FileName,info);
|
||
MessageBox.Show ("Ðżþ±£´æ³É¹¦£¡");
|
||
}
|
||
break;
|
||
|
||
case 3:
|
||
btnAdd_Click();
|
||
break;
|
||
|
||
default:
|
||
|
||
MessageBox.Show ("´Ë¹¦ÄÜ»¹Ã»ÓÐÍêÉÆ");
|
||
break;
|
||
|
||
}
|
||
}
|
||
|
||
private void menuItem7_Click(object sender, System.EventArgs e)
|
||
{
|
||
btnAdd_Click();
|
||
}
|
||
|
||
private void SendMailForm_Load(object sender, System.EventArgs e)
|
||
{
|
||
ltAttachment .Visible =false;
|
||
this.splitter1 .Visible =false;
|
||
}
|
||
|
||
|
||
|
||
//¸½¼þµÄ"ɾ³ý"²Ù×÷
|
||
private void menuItem10_Click(object sender, System.EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if(ltAttachment .Items .Count >1)
|
||
{
|
||
//ÒòΪÔÚÌí¼ÓÒ»¸ö¸½¼þµÄʱºò£¬¸ÕºÃÒ²ÊÇÌí¼ÓÁËÒ»¸öListViewÖеÄÎļþÃû
|
||
//ËùÒÔËûÃǵÄË÷ÒýÖµÊÇÏàͬµÄ¡£ËùÒÔ¿ÉÒÔͨ¹ýÑ¡ÖеÄListViewµÄË÷ÒýÖµÀ´É¾³ý¸½¼þ
|
||
array.RemoveAt (ltAttachment.SelectedItems [0].Index );
|
||
ltAttachment .Items .RemoveAt (ltAttachment .SelectedIndices[0] );
|
||
}
|
||
else if(ltAttachment .Items .Count ==1)
|
||
|
||
{
|
||
array.RemoveAt(ltAttachment .SelectedItems [0].Index);
|
||
ltAttachment .Items .RemoveAt (ltAttachment .SelectedIndices[0] );
|
||
this.splitter1 .Visible =false;
|
||
ltAttachment .Visible =false;
|
||
}
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
MessageBox.Show (ex.ToString ());
|
||
}
|
||
}
|
||
|
||
private void menuItem9_Click_1(object sender, System.EventArgs e)
|
||
{
|
||
btnAdd_Click();
|
||
|
||
}
|
||
|
||
private void menuItem15_Click_1(object sender, System.EventArgs e)
|
||
{
|
||
ltAttachment .View =View.LargeIcon ;
|
||
}
|
||
|
||
private void menuItem17_Click(object sender, System.EventArgs e)
|
||
{
|
||
ltAttachment .View =View.SmallIcon ;
|
||
|
||
}
|
||
|
||
private void menuItem16_Click_1(object sender, System.EventArgs e)
|
||
{
|
||
ltAttachment .View =View.List;
|
||
}
|
||
|
||
|
||
//"´ò¿ª"²Ù×÷
|
||
private void menuItem12_Click(object sender, System.EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (this.ltAttachment.SelectedItems[0].ToString() != "")
|
||
{
|
||
int length = this.ltAttachment.SelectedItems[0].ToString().Length;
|
||
string ss = this.ltAttachment.SelectedItems[0].ToString().Substring(15, length - 16);
|
||
ShellExecute(IntPtr.Zero, "Open", ss, null, null, 0);
|
||
}
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
MessageBox.Show (ex.ToString ());
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
//ÒÔϵÄÁ½¸öʼþÊÇÓÃÀ´Ö§³ÖÔÚÌí¼Ó¸½¼þʱºòµÄÍϷŲÙ×÷µÄ
|
||
private void listView1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
||
{
|
||
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||
|
||
|
||
for (int i = 0; i < files.Length; i++)
|
||
{
|
||
array.Add(files[i]);
|
||
AddIcon(files[i]);
|
||
}
|
||
}
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
MessageBox.Show (ex.ToString ());
|
||
}
|
||
|
||
|
||
}
|
||
|
||
private void listView1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
||
e.Effect = DragDropEffects.Copy;
|
||
else
|
||
e.Effect = DragDropEffects.None;
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
MessageBox.Show (ex.ToString ());
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
}
|