Live Chat Icon For mobile
Live Chat Icon

ASP.NET FAQ - Mail

Find answers for the most frequently asked questions
Expand All Collapse All

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.
For more information refer Read Access to the Everyone Group Is Removed After You Install Exchange 2000 SP3

Permalink

This is a network related error. Your application cannot connect to the mail server specified.
Make sure that the following are true about SmtpMail.SmtpServer:

  • Is a valid SMTP Server
  • Make sure that the server System.Web.Mail is running or can connect to the mail server. Some times firewalls or proxy servers can get in the way.
  • Try specifying the value by IP address. Poor DNS resolution can sometimes hinder name lookups.
  • Make sure that the mail server is running at port 25.
  • If you did not specify a SmtpMail.SmtpServer property, or if SmtpMail.SmtpServer points to ‘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.
Permalink

VB.NET


Dim mailattach As New MailAttachment(Server.MapPath('<yourfilename>'))
mail.Attachments.Add(mailattach)

C#


MailAttachment mailattach = new MailAttachment( Server.MapPath( '<yourfilename>' ) );  
mail.Attachments.Add( mailattach );	
Permalink

Install the SMTP virtual server that is part of IIS.

  • You will need your Windows installation CD.
  • Use Add or Remove Programs in the Windows Control Panel to launch Add/Remove Windows Components.
  • Select Internet Information Services (IIS) and then click Details.
  • Check SMTP Service and then click OK.
  • 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.
  3. In the Access tab, click Connection.
  4. Select Only the list below, click Add and add the IP 127.0.0.1. This restricts connections to just the local computer, i.e., localhost. Close the Connection dialog box.
  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.

Permalink

Use System.Web.Mail
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.

For more details refer System.Web.Mail Namespace

Permalink

VB.NET


Protected Sub Application_Error(sender As [Object], e As EventArgs)
   	Dim ex As Exception = Server.GetLastError()
   	Dim mail As New MailMessage()
   	mail.To = 'manag@syncfusion.com'
   	mail.From = 'admin@syncfusion.com'
   	mail.Subject = ex.Message.ToString()
   	mail.Body = ex.ToString()
   	mail.BodyFormat = MailFormat.Html
   	SmtpMail.SmtpServer = 'localhost'
   	SmtpMail.Send(mail)
End Sub ’Application_Error

C#


protected void Application_Error(Object sender, EventArgs e)
{ 
	Exception ex = Server.GetLastError ();
	MailMessage mail = new MailMessage();
	mail.To = 'manag@syncfusion.com';
	mail.From = 'admin@syncfusion.com';
	mail.Subject = ex.Message.ToString ();
	mail.Body =ex.ToString  ();
	mail.BodyFormat = MailFormat.Html;
	SmtpMail.SmtpServer = 'localhost';  
	SmtpMail.Send( mail );
}
Permalink

Use namespace System.IO and System.NET
VB.NET

 ’In Page_Load
Dim mailcontenturl As String = 'http://www.syncfusion.com'
Dim mail As New MailMessage()
mail.To = 'manag@syncfusion.com'
mail.From = 'admin@syncfusion.com'
mail.Subject = 'Test.'

’To send webpage 
mail.Body = GetHTML(mailcontenturl)
mail.BodyFormat = MailFormat.Html
mail.UrlContentBase = mailcontenturl

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.syncfusion.com';
MailMessage mail = new MailMessage();
mail.To = 'manag@syncfusion.com';
mail.From = 'admin@syncfusion.com';
mail.Subject = 'Test.';

//To send webpage 
mail.Body = GetHTML ( mailcontenturl );
mail.BodyFormat = MailFormat.Html;
mail.UrlContentBase = mailcontenturl;
		
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;
}
Permalink

VB.NET


Dim mail As New MailMessage()
mail.To = 'manag@syncfusion.com'
mail.From = 'admin@syncfusion.com'
mail.Subject = 'Test.'
mail.BodyFormat = MailFormat.Html
mail.Body = 'Test Message'
SmtpMail.SmtpServer = 'localhost' ’your real server goes here
SmtpMail.Send(mail)

C#


MailMessage mail = new MailMessage();
mail.To = 'manag@syncfusion.com';
mail.From = 'admin@syncfusion.com';
mail.Subject = 'Test.';
mail.BodyFormat = MailFormat.Html;
mail.Body = 'Test Message';
SmtpMail.SmtpServer = 'localhost';  //your real server goes here
SmtpMail.Send( mail );
Permalink

VB.NET


Dim mail As New MailMessage()
mail.To = 'admin@syncfusion.com'
mail.From = 'manag@syncfusion.com'
mail.Subject = 'Test.'
mail.Body = 'Test Message'
SmtpMail.SmtpServer = 'localhost' ’your real server goes here
SmtpMail.Send(mail)

C#


MailMessage mail = new MailMessage();
mail.To = 'admin@syncfusion.com';
mail.From = 'manag@syncfusion.com';
mail.Subject = 'Test.';
mail.Body = 'Test Message';
SmtpMail.SmtpServer = 'localhost';  //your real server goes here
SmtpMail.Send( mail );
Permalink

Share with

Couldn't find the FAQs you're looking for?

Please submit your question and answer.