有参数的程序,可以被调用
using System;using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;
namespace SendMail
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
static void Main(string[] Arrs)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
if (Arrs == null) { WriteErr("No Parameter"); return; }
string sfrom = "";
string sto = "";
string scc = "";
string sbcc = "";
string ssubject = "";
string sbody = "";
string satt = "";
string[] Arr = Arrs.Split('|');
if (Arr.Length > 0)
sfrom = Arr;
if (Arr.Length > 1)
sto = Arr;
if (Arr.Length > 2)
scc = Arr;
if (Arr.Length > 3)
sbcc = Arr;
if (Arr.Length > 4)
ssubject = Arr;
if (Arr.Length > 5)
sbody = Arr;
if (Arr.Length > 6)
satt = Arr;
if (sfrom == "" || (sto == "" && scc == "")) { WriteErr("Parameter Error"); return; }
SendMail.Mail SendMail = new SendMail.Mail();
string Err = SendMail.SendMail(sfrom, sto, scc, sbcc, ssubject, sbody, satt);
WriteErr(Err);
}
static void WriteErr(string strErr)
{
if (strErr == "") return;
System.IO.StreamWriter sw;
sw = new StreamWriter(Application.StartupPath + "\\Error.err", false, System.Text.Encoding.Default);
sw.WriteLine(strErr);
sw.Flush();
sw.Close();
}
}
}
页:
[1]