Exchange Hosting and Web Hosting
Search:
Lookup Article by ID:
Web Hosting > Mail Server > Sending Mail via Script
 
 

How do I send mail from Windows 2008 server/IIS7?

 

You can use the following components to send mail from Windows 2008/IIS7 web server:

System.Net.Mail:

For detailed description of System.Net.Mail namespace please use following links:

  •     http://msdn.microsoft.com/en-us/library/system.net.mail.aspx
  •     http://www.systemnetmail.com

The System.Net.Mail namespace supports SMTP authentication, so you can use either scriptmail.intermedia.net mail server or your POP mail server ''mail.domain.name" to send mail from scripts. The below examples are written in C# and VBScript, they will work on all our Windows 2008 servers.

C#

<%@ Import Namespace="System.Net.Mail"%>
<script language="C#" Debug="true" runat="server">
    void Page_Load()
    {
            try
            {
            MailMessage oMsg = new MailMessage();
            oMsg.From = new MailAddress("mailbox@yourdomain.com");
            oMsg.To.Add("recipient@theirdomain.com");
            oMsg.Subject = "This is an email";
            oMsg.Body = "<HTML><BODY><B>Hello World!</B></BODY></HTML>";
            SmtpClient smtp = new SmtpClient("scriptmail.intermedia.net");
            smtp.Send(oMsg);
            oMsg = null;
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
            }
        }
</script>


VBScript

<%@ Import Namespace="System.Net.Mail"%>
<script language="VBScript" Debug="true" runat="server">
    sub Page_Load()
        Dim oMsg As New MailMessage()
        oMsg.From = New MailAddress("mailbox@yourdomain.com")
        oMsg.To.Add("recipient@theirdomain.com")
        oMsg.Subject = "This is an email"
        oMsg.Body = "<HTML><BODY><B>Hello World!</B></BODY></HTML>"
        Dim smtp As New SmtpClient("scriptmail.intermedia.net")
        smtp.Send(oMsg)
        oMsg = Nothing
    end sub
</script>



CDOSYS

To send mail using classic ASP, you can also use CDOSYS library. For more information about the library, please check here. Please note that this is a pretty old library and it is recommended to use System.Net.Mail instead.

You need to use scriptmail.intermedia.net mail server to send mail from scripts. The below example is written in VBScript.

<%
Set myMail=CreateObject("CDO.Message")
    myMail.Subject="This is an email"
    myMail.From="
mailbox@yourdomain.com"
    myMail.To="recipient@theirdomain.com"
    myMail.TextBody="Hello world!"
    myMail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
    'SMTP server
    myMail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="scriptmail.intermedia.net"
    'SMTP port
    myMail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
    myMail.Configuration.Fields.Update
    myMail.Send
    set myMail=nothing
%>

Please note that System.Web.Mail component is not supported on Windows 2008/IIS7 servers.

To send mail from Windows 2000/2003 server, please refer to our knowledge base article #1006.

 

 
If you did not find this article helpful let us know how we can improve the content
 
Article ID: 1579
Keywords: send mail IIS7 Windows 2008 CDOSYS System.Net.Mail
Product: Shared Web, Dedicated Web
Last Modified: 6/27/2010 9:54:29 AM
Direct Path: http://hosting.intermedia.net/support/kb/viewKBArticle.asp?id=1579
 

 

Microsoft Exchange 2007 Hosting | Hosted Exchange Server
Microsoft Exchange Server Outsourcing | Private Label Exchange Hosting
Windows 2008 Hosting | ASP.NET Hosting | Web Hosting | MS SQL Server 2008 Hosting

Copyright © Intermedia, Inc. 1995 - 2009. All Rights Reserved.

Users of this site agree to be bound by the Intermedia Service Agreement,
Service Level Agreement, and Acceptable Use Policies.
Legal | AUP | Privacy Statement