本文整理汇总了C#中System.Web.Mail.SmtpMail类的典型用法代码示例。如果您正苦于以下问题:C# SmtpMail类的具体用法?C# SmtpMail怎么用?C# SmtpMail使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SmtpMail类属于System.Web.Mail命名空间,在下文中一共展示了SmtpMail类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisplayUsage
//引入命名空间
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 SomeOne@Contoso.com;SomeOther@Contoso.com Me@contoso.com 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());
}
}
}
}