PHP Code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace SAEC
{
public class frmMain : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.RadioButton optName;
private System.Windows.Forms.RadioButton optIPAddress;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.RadioButton optSMTP;
private System.Windows.Forms.RadioButton optPOP3;
private System.Windows.Forms.TextBox txtServerName;
private System.Windows.Forms.TextBox txtFrom;
private System.Windows.Forms.TextBox txtTo;
private System.Windows.Forms.TextBox txtSubject;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtMessage;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox txtLog;
private System.ComponentModel.Container components = null;
public frmMain()
{
InitializeComponent();
}
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.button1 = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtServerName = new System.Windows.Forms.TextBox();
this.optIPAddress = new System.Windows.Forms.RadioButton();
this.optName = new System.Windows.Forms.RadioButton();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.txtMessage = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.txtSubject = new System.Windows.Forms.TextBox();
this.txtTo = new System.Windows.Forms.TextBox();
this.txtFrom = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.label5 = new System.Windows.Forms.Label();
this.txtLog = new System.Windows.Forms.TextBox();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.optPOP3 = new System.Windows.Forms.RadioButton();
this.optSMTP = new System.Windows.Forms.RadioButton();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox4.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(384, 536);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Send";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.txtServerName,
this.optIPAddress,
this.optName});
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(320, 96);
this.groupBox1.TabIndex = 5;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Server Data";
//
// txtServerName
//
this.txtServerName.Location = new System.Drawing.Point(104, 24);
this.txtServerName.Name = "txtServerName";
this.txtServerName.Size = new System.Drawing.Size(200, 22);
this.txtServerName.TabIndex = 2;
this.txtServerName.Text = "";
//
// optIPAddress
//
this.optIPAddress.Enabled = false;
this.optIPAddress.Location = new System.Drawing.Point(16, 56);
this.optIPAddress.Name = "optIPAddress";
this.optIPAddress.Size = new System.Drawing.Size(80, 24);
this.optIPAddress.TabIndex = 1;
this.optIPAddress.Text = "IP-Address";
//
// optName
//
this.optName.Checked = true;
this.optName.Location = new System.Drawing.Point(16, 24);
this.optName.Name = "optName";
this.optName.Size = new System.Drawing.Size(72, 24);
this.optName.TabIndex = 0;
this.optName.TabStop = true;
this.optName.Text = "Name";
//
// groupBox2
//
this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.txtMessage,
this.label4,
this.txtSubject,
this.txtTo,
this.txtFrom,
this.label3,
this.label2,
this.label1});
this.groupBox2.Location = new System.Drawing.Point(8, 128);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(464, 296);
this.groupBox2.TabIndex = 6;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "EMail Data";
//
// txtMessage
//
this.txtMessage.Location = new System.Drawing.Point(128, 128);
this.txtMessage.Multiline = true;
this.txtMessage.Name = "txtMessage";
this.txtMessage.Size = new System.Drawing.Size(312, 152);
this.txtMessage.TabIndex = 12;
this.txtMessage.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(16, 128);
this.label4.Name = "label4";
this.label4.TabIndex = 11;
this.label4.Text = "Message:";
//
// txtSubject
//
this.txtSubject.Location = new System.Drawing.Point(128, 88);
this.txtSubject.Name = "txtSubject";
this.txtSubject.Size = new System.Drawing.Size(312, 22);
this.txtSubject.TabIndex = 10;
this.txtSubject.Text = "";
//
// txtTo
//
this.txtTo.Location = new System.Drawing.Point(128, 56);
this.txtTo.Name = "txtTo";
this.txtTo.Size = new System.Drawing.Size(312, 22);
this.txtTo.TabIndex = 9;
this.txtTo.Text = "";
//
// txtFrom
//
this.txtFrom.Location = new System.Drawing.Point(128, 24);
this.txtFrom.Name = "txtFrom";
this.txtFrom.Size = new System.Drawing.Size(312, 22);
this.txtFrom.TabIndex = 8;
this.txtFrom.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 88);
this.label3.Name = "label3";
this.label3.TabIndex = 7;
this.label3.Text = "Subject:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 56);
this.label2.Name = "label2";
this.label2.TabIndex = 6;
this.label2.Text = "To:";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 24);
this.label1.Name = "label1";
this.label1.TabIndex = 5;
this.label1.Text = "From:";
//
// groupBox3
//
this.groupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label5,
this.txtLog});
this.groupBox3.Location = new System.Drawing.Point(8, 440);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(464, 88);
this.groupBox3.TabIndex = 7;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Log Data";
//
// label5
//
this.label5.Location = new System.Drawing.Point(16, 32);
this.label5.Name = "label5";
this.label5.TabIndex = 1;
this.label5.Text = "Communication:";
//
// txtLog
//
this.txtLog.AcceptsReturn = true;
this.txtLog.Location = new System.Drawing.Point(128, 24);
this.txtLog.Multiline = true;
this.txtLog.Name = "txtLog";
this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtLog.Size = new System.Drawing.Size(312, 48);
this.txtLog.TabIndex = 0;
this.txtLog.Text = "";
//
// groupBox4
//
this.groupBox4.Controls.AddRange(new System.Windows.Forms.Control[] {
this.optPOP3,
this.optSMTP});
this.groupBox4.Location = new System.Drawing.Point(344, 8);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(128, 96);
this.groupBox4.TabIndex = 8;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Protocol Data";
//
// optPOP3
//
this.optPOP3.Enabled = false;
this.optPOP3.Location = new System.Drawing.Point(16, 56);
this.optPOP3.Name = "optPOP3";
this.optPOP3.TabIndex = 1;
this.optPOP3.Text = "POP3 Server";
//
// optSMTP
//
this.optSMTP.Checked = true;
this.optSMTP.Location = new System.Drawing.Point(16, 24);
this.optSMTP.Name = "optSMTP";
this.optSMTP.TabIndex = 0;
this.optSMTP.TabStop = true;
this.optSMTP.Text = "SMTP Server";
//
// frmMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(488, 573);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.groupBox4,
this.groupBox3,
this.groupBox2,
this.groupBox1,
this.button1});
this.Font = new System.Drawing.Font("Arial Unicode MS", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "frmMain";
this.Opacity = 0.89999997615814209;
this.Text = "Ghost Mailer";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new frmMain());
}
private void SendMailSMTP()
{
// create server SMTP with port 25
TcpClient SmtpServ;
string Data;
byte[] szData;
string CRLF = "\r\n";
if( optIPAddress.Checked )
{
SmtpServ = new TcpClient();// IP .Text,25);
}
else
{
SmtpServ = new TcpClient( txtServerName.Text, 25 );
}
try
{
// initialization
NetworkStream NetStrm = SmtpServ.GetStream();
StreamReader RdStrm= new StreamReader(SmtpServ.GetStream());
txtLog.Text += RdStrm.ReadLine();
txtLog.Text += CRLF;
// say hello to server and send response into log report
Data = "HELO " + txtServerName.Text + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
txtLog.Text += Data + CRLF;
txtLog.Text += RdStrm.ReadLine();
txtLog.Text += CRLF;
// send sender data
Data = "MAIL FROM: " + "<" + txtFrom.Text + ">" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
txtLog.Text += Data + CRLF;
txtLog.Text += RdStrm.ReadLine();
txtLog.Text += CRLF;
// send receiver data
Data = "RCPT TO: " + "<" + txtTo.Text + ">" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
txtLog.Text += Data + CRLF;
txtLog.Text += RdStrm.ReadLine();
txtLog.Text += CRLF;
// send DATA
Data = "DATA " + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
txtLog.Text += Data + CRLF;
txtLog.Text += RdStrm.ReadLine();
txtLog.Text += CRLF;
// send content data
Data = "SUBJECT: " + txtSubject.Text + CRLF + txtMessage.Text + CRLF + "." + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
txtLog.Text += Data + CRLF;
txtLog.Text += RdStrm.ReadLine();
txtLog.Text += CRLF;
// quit from server SMTP
Data = "QUIT " + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
txtLog.Text += Data + CRLF;
txtLog.Text += RdStrm.ReadLine();
txtLog.Text += CRLF;
// close connection
NetStrm.Close();
RdStrm.Close();
txtLog.Text += "Close connection";
txtLog.Text +="Send mail successly..";
}
catch(InvalidOperationException err)
{
txtLog.Text += "Error: "+ err.ToString();
}
}
private void button1_Click(object sender, System.EventArgs e)
{
// change cursor into wait cursor
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
button1.Enabled = false;
txtLog.Text = "";
if( optSMTP.Checked )
{
SendMailSMTP();
}
else
{
//POP3
}
button1.Enabled = true;
// back to normal cursor
Cursor.Current = cr;
}
}
}
This is a very simple mail sending program for windows. POP has not been implemented yet, so some branches might not do anything useful