Files
mono/mcs/class/System.Web/System.Web.Mail/SmtpMail.cs
T
Gonzalo Paniagua Javier 81f6e15911 2003-07-03 Gonzalo Paniagua Javier <[email protected]>
* MailAddress.cs: return null instead of exception when the address is
	empty.

	* MailAddressCollection.cs: ignore null addresses.
	* SmtpMail.cs: add the exception we get as inner exception so we know
	where the error is.

	Fixes bug #45746.

svn path=/trunk/mcs/; revision=15886
2003-07-03 11:16:03 +00:00

88 lines
1.8 KiB
C#

//
// System.Web.Mail.SmtpMail.cs
//
// Author:
// Lawrence Pit ([email protected])
// Per Arneng ([email protected]) (SmtpMail.Send)
//
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.IO;
using System.Reflection;
namespace System.Web.Mail
{
/// <remarks>
/// </remarks>
public class SmtpMail
{
private static string smtpServer = "localhost";
// Constructor
private SmtpMail ()
{
/* empty */
}
// Properties
public static string SmtpServer {
get { return smtpServer; }
set { smtpServer = value; }
}
public static void Send (MailMessage message)
{
try {
// wrap the MailMessage in a MailMessage wrapper for easier
// access to properties and to add some functionality
MailMessageWrapper messageWrapper = new MailMessageWrapper( message );
SmtpClient smtp = new SmtpClient (smtpServer);
smtp.Send (messageWrapper);
smtp.Close ();
} catch (SmtpException ex) {
// LAMESPEC:
// .NET sdk throws HttpException
// for some reason so to be compatible
// we have to do it to :(
throw new HttpException (ex.Message, ex);
} catch (IOException ex) {
throw new HttpException (ex.Message, ex);
} catch (FormatException ex) {
throw new HttpException (ex.Message, ex);
} catch (SocketException ex) {
throw new HttpException (ex.Message, ex);
}
}
public static void Send (string from, string to, string subject, string messageText)
{
MailMessage message = new MailMessage ();
message.From = from;
message.To = to;
message.Subject = subject;
message.Body = messageText;
Send (message);
}
}
} //namespace System.Web.Mail