Professional Documents
Culture Documents
VB.NET
C#
VB.NET
C#
The System.Web.Mail namespace contains classes that enable you to construct and send messages using the
CDOSYS (Collaboration Data Objects for Windows 2000) message component. The mail message is delivered
either through the SMTP mail service built into Microsoft Windows 2000 or through an arbitrary SMTP server.
The classes in this namespace can be used from ASP.NET or from any managed application.
• Use Add or Remove Programs in the Windows Control Panel to launch Add/Remove Windows
Components.
• The installation process will prompt you for your Windows CD and will install the SMTP virtual server.
After installing the SMTP server (also reboot), configure it by following these steps:
1. In the Control Panel, choose Administrative Tools, and then choose Internet Information Services.
2. Open the node for your computer, right-click the Default SMTP Virtual Server node and choose
Properties.
4. Select Only the list below, click Add and add the IP 127.0.0.1. This restricts connections to just the
5. Click Relay and repeat Step 5 to allow only localhost to relay through this server.
In your firewall or router (or both), close incoming port 25. This is an important security measure
that will prevent spammers from finding your SMTP server and using it to relay spam.
18.5 Why do I get the error message "The transport failed to connect to
the server "?
This is a network related error. Your application cannot connect to the mail server specified.
• Make sure that the server System.Web.Mail is running or can connect to the mail server. Some times
• Try specifying the value by IP address. Poor DNS resolution can sometimes hinder name lookups.
"localhost" (or the equivalent), be sure the SMTP Service is running on port 25.
• For testing purposes change the MailMessage.From and MailMessage.To properties to an address that
exists on SmtpMail.SmtpServer. Some times this exception is thrown, when it really is a relay issue.
18.6 Why do I get the error message "The SendUsing configuration value
is invalid"?
This problem occurs because read access to the Internet Information Services (IIS) metabase and the
Microsoft Active Directory directory service has been removed for the Everyone group. This access has been
removed because of a security modification in Exchange 2000 Server SP3. CDOEX, CDOSYS, and
System.Web.Mail must have access to the IIS metabase to access information about the location of the
pickup directory path. This behavior occurs when you use the Sendusingpickup method and if this information
is not specified in the application code. Because access is restricted, the non-administrative user under whose
security context the application is running cannot read this information from the IIS metabase and Active
Directory. Fore more information refer Read Access to the Everyone Group Is Removed After You Install
VB.NET
C#
'In Page_Load
Dim mailcontenturl As String = "http://www.megasolutions.net"
Dim mail As New MailMessage()
mail.To = "manag@megasolutions.net"
mail.From = "admin@megasolutions.net"
mail.Subject = "Test."
SmtpMail.SmtpServer = "localhost"
SmtpMail.Send(mail)
'Function GetHTML
Private Function GetHTML(url As String) As String
Dim wReq As WebRequest = System.Net.HttpWebRequest.Create(url)
Dim sr As New StreamReader(wReq.GetResponse().GetResponseStream())
Dim result As String = sr.ReadToEnd()
sr.Close()
Return result
End Function 'GetHTML
C#
//In Page_Load
string mailcontenturl ="http://www.megasolutions.net";
MailMessage mail = new MailMessage();
mail.To = "manag@megasolutions.net";
mail.From = "admin@megasolutions.net";
mail.Subject = "Test.";
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send( mail );
//Function GetHTML
private string GetHTML( string url )
{
WebRequest wReq= System.Net.HttpWebRequest.Create(url);
StreamReader sr = new StreamReader( wReq.GetResponse().GetResponseStream() );
string result = sr.ReadToEnd();
sr.Close();
return result;
}
VB.NET
C#
VB.NET
C#
VB.NET
C#
18.13 Why do I get the error message "Sender address rejected: need
fully-qualified address "?
18.14 How do I resolve the error "The server rejected one or more
recipient addresses. The server response was: 503 This mail server
requires authentication. Please check your mail client settings"?
CDOSYS supports username and password authentication, and version 1.1 of the .NET Framework added the
Fields property to the MailMessage class, which lets you set arbitrary fields of the underlying CDOSYS object.
VB.NET
mailMessage.To = "abc@megasolutions.net;xyz@megasolutions.net"
C#
mailMessage.To = "abc@megasolutions.net;xyz@megasolutions.net";
18.16 How can I use a "friendly name" in the To and From properties?
VB.NET
C#
18.17 Why do I get the error message "550 5.7.1 Unable to relay for xxx
or 550 not local host xxx, not a gateway "?
The SMTP server is not configured to allow you to relay. If you are working with a local SMTP server, you can