调用外部文件是什么意思?最简单的发邮件的代码:
Example
The following example can be compiled to a console application that is used to send email from a command line. If you compile the example to a file named MailMessage.exe, use the executable file to send email as follows:MailMessage [email protected] [email protected] test hello using System;
using System.Web.Mail;
namespace SendMail
{
class usage
{
public void DisplayUsage()
{
Console.WriteLine("Usage SendMail.exe <to> <from> <subject> <body>");
Console.WriteLine("<to> the addresses of the email recipients");
Console.WriteLine("<from> your email address");
Console.WriteLine("<subject> subject of your email");
Console.WriteLine("<body> the text of the email");
Console.WriteLine("Example:");
Console.WriteLine("SendMail.exe [email protected];[email protected] [email protected] Hi hello");
}
}
class Start
{
// The main entry point for the application.
[STAThread]
static void Main(string[] args)
{
try
{
try
{
MailMessage Message = new MailMessage();
Message.To = args[0];
Message.From = args[1];
Message.Subject = args[2];
Message.Body = args[3]; try
{
SmtpMail.SmtpServer = "your mail server name goes here";
SmtpMail.Send(Message);
}
catch(System.Web.HttpException ehttp)
{
Console.WriteLine("{0}", ehttp.Message);
Console.WriteLine("Here is the full error message output");
Console.Write("{0}", ehttp.ToString());
}
}
catch(IndexOutOfRangeException)
{
usage use = new usage();
use.DisplayUsage();
}
}
catch(System.Exception e)
{
Console.WriteLine("Unknown Exception occurred {0}", e.Message);
Console.WriteLine("Here is the Full Message output");
Console.WriteLine("{0}", e.ToString());
}
}
}
}
Example
The following example can be compiled to a console application that is used to send email from a command line. If you compile the example to a file named MailMessage.exe, use the executable file to send email as follows:MailMessage [email protected] [email protected] test hello using System;
using System.Web.Mail;
namespace SendMail
{
class usage
{
public void DisplayUsage()
{
Console.WriteLine("Usage SendMail.exe <to> <from> <subject> <body>");
Console.WriteLine("<to> the addresses of the email recipients");
Console.WriteLine("<from> your email address");
Console.WriteLine("<subject> subject of your email");
Console.WriteLine("<body> the text of the email");
Console.WriteLine("Example:");
Console.WriteLine("SendMail.exe [email protected];[email protected] [email protected] Hi hello");
}
}
class Start
{
// The main entry point for the application.
[STAThread]
static void Main(string[] args)
{
try
{
try
{
MailMessage Message = new MailMessage();
Message.To = args[0];
Message.From = args[1];
Message.Subject = args[2];
Message.Body = args[3]; try
{
SmtpMail.SmtpServer = "your mail server name goes here";
SmtpMail.Send(Message);
}
catch(System.Web.HttpException ehttp)
{
Console.WriteLine("{0}", ehttp.Message);
Console.WriteLine("Here is the full error message output");
Console.Write("{0}", ehttp.ToString());
}
}
catch(IndexOutOfRangeException)
{
usage use = new usage();
use.DisplayUsage();
}
}
catch(System.Exception e)
{
Console.WriteLine("Unknown Exception occurred {0}", e.Message);
Console.WriteLine("Here is the Full Message output");
Console.WriteLine("{0}", e.ToString());
}
}
}
}
解决方案 »
- 一个线程卡了,另一个线程会卡么?
- 正则表达式写法,在字符串中提取有效数据
- 怎么在 dataGrid 的单元格中显示图片?
- 如何实现如此效果:单击按钮,相当于按了快捷键A键,用WPF实现
- 声明enum的时候从int继承,为什么该enum还是不能直接给int赋值呢?
- 线程返回值问题
- 如何利用反射来创建委托
- textbox的一个问题,百思不得其解
- 如何让PrintPreviewControl控件在Document.DefaultSetting更改生效后立即显示新设置的预览页面?
- nutomation服务器不能创建对象? 怎么回事
- 帮忙看一下代码, 是导出Excel到Datagrid,编译可以通过,单执行就会报异常,请高手指点
- 在c#中如何使用随机数。在线等待,谢谢了
Message.Attachments.Add(new MailAttachment(filePath,MailEncoding.Base64))这样如果你的IIS装了SMTP,那就可以发送邮件了
或者指定一个SMTP Server(不用认证的才可以)
SmtpMail.SmtpServer = "mail.xxx.com";
System.Diagnostics.Process.Start( "mailto:[email protected]" );