Thứ Tư, 13 tháng 6, 2012

Configure SMTP E-Mail in IIS 7

Introduction

To send e-mail from a PHP application using the System.Net.Mail API, you must configure Simple Mail Transfer Protocol (SMTP) e-mail. Configuring e-mail services tells the System.Net.Mail application programming interface (API) to which SMTP server to deliver the e-mail generated by your application. Mail can be delivered immediately, or it can be delivered to a file location on disk where it can be retrieved for delivery later. For example, a company can provide an e-mail link for sending feedback messages or for requesting information.

The procedures for configuring SMTP e-mail can be performed at the following levels in Internet Information Services 7 (IIS 7):

  • Web server
  • Site
  • Application
  • Physical and virtual directories
  • File (URL)

Install SMTP

The SMTP server is not installed by default.

1. Open Server Manager by right-clicking on My Computer, and selecting Manage. (Alternately, open Control Panel, click on Programs and Features, and then select Turn Windows features on or off.)

2. Under Features, select Add Features.

3. Select the SMTP Server check box.

4. Click Add Required Role Services. If there are any missing roles required for the SMTP installation, Windows Server® 2008 R2 or Windows Server® 2008 installs them. Click Next.

5. You need to step through the entire wizard again, even though IIS is already installed (IIS 6 Management Compatibility and the IIS 6 Management Console must be installed for SMTP to work).

Figure 1: Confirm Installation Selections

6. Press Close when installation is complete.

Configure SMTP E-Mail for a Web Application

Once you add SMTP, you can configure it for your PHP applications. This can be done by using the user interface (UI), by running Appcmd.exe commands from a command prompt, by editing configuration files directly, or by writing Windows® Management Instrumentation (WMI) scripts. Note that you must have IIS 7 installed before enabling SMTP.

Use the User Interface

1. Open Internet Information Services (IIS) Manager, and then navigate to the level you want to manage.

2. In Features View, double-click SMTP E-mail.

3. On the SMTP E-mail page, type the e-mail address of the sender in the E-mail address text box.

4. On the SMTP E-mail page, select one of the following delivery methods:

a. Deliver e-mail to SMTP server: to deliver e-mail messages immediately. This requires an operational SMTP server for which the user has credentials.

b. Store e-mail in pickup directory: to store e-mails in a file location on disk for later delivery by the PHP application (or by a Microsoft® ASP.NET application or by a user).

5. If Deliver e-mail to SMTP server is selected, do the following:

a. Type the unique name of your SMTP server in the SMTP Server text box, or select the Use localhost check box to set the name to LocalHost. Setting the name to LocalHost means that ASP.NET uses an SMTP server on the local computer. Typically, this is the default SMTP virtual server.

b. Enter a TCP port in the Port text box. Port 25 is the SMTP standard TCP port and is the default setting. More than one virtual server can use the same TCP port if all servers are configured by using different IP addresses.

c. Under Authentication Settings, specify the authentication mode and credentials if your SMTP server requires these.

6. If Store e-mail in pickup directory is selected, type the batch e-mail location in the Store e-mail in pickup directory text box.

7. Click Apply in the Actions pane.

Use the Command Line

You can configure IIS so that e-mail is delivered immediately or stored for later delivery.

Deliver e-mail messages immediately

To configure SMTP e-mail to deliver e-mail messages immediately, use the following syntax:

C:\%windir%\system32\inetsrv\appcmd set config /commit:WEBROOT /section:smtp /from: string /deliveryMethod:network /network.port: int /network.defaultCredentials:True|False /network.host:string /network.userName:string /network.password:string

The variable from string is the e-mail address of the sender. The variable /deliveryMethod:network configures IIS to deliver e-mail messages immediately. The variable /network.port int sets the TCP port that is used by IIS to deliver e-mail messages. The variable /network.host string specifies the host used for SMTP transactions. The variable network.defaultCredentials:True|False enables or disables authentication using the default network credentials. If defaultCredentials is set to True, Kerberos or NTLM are used if the server supports these protocols. The variables network.userName:string and network. password:string set a basic authentication user name and password.

Store e-mails for later delivery

To configure SMTP e-mail to store e-mails in a file location on disk for later delivery by an application, such as an ASP.NET application, or by a user, such as an administrator, use the following syntax:

C:\%windir%\system32\inetsrv\appcmd set config /commit:WEBROOT /section:smtp /from: string /deliveryMethod:PickupDirectoryFromIis|SpecifiedPickupDirectory /SpecifiedPickupDirectory:string

The variable from string is the e-mail address of the sender. The variable/deliveryMethod:PickupDirectoryFromIis|SpecifiedPickupDirectory string configures IIS to store e-mails in a file location on disk for later delivery. The variable /SpecifiedPickupDirectory string sets the file location on disk in which to store the e-mail messages for later delivery.

Note that when you use Appcmd.exe to configure the element at the global level in IIS 7, you must specify /commit:WEBROOT in the command so that configuration changes are made to the root Web.config file instead of the ApplicationHost.config file.

Edit the Configuration Files

1. First, configure the Php.ini file. Open the Php.ini file, and find the entry:

[mail function]

2. Set the following values:

SMTP=localhost
sendmail_from = string
smtp_port=25

Note that the default value is localhost, so there is no need to change this if SMTP is installed locally.

a. Save and close the Php.ini file.

3.Enable Relay for localhost:

a. Open the Internet Information Services (IIS) 6.0 Manager.

b. Right-click on Default SMTP Virtual Server.

4. On the Properties page, open the Access tab, and then click on Connection. You can see which server or IP addresses are allowed to connect to the server.

5. If the IP address 127.0.0.1 is not listed, add it using the Add button. You may also add your server IP address to the list.

Figure 2: Enable Relay for localhost

6. Click OK to accept the information.

7. Click the Relay button on the Access tab, and set up the relay options for the server. Ensure that localhost and the IP address 127.0.0.1 are granted permission to relay mail.

8. Click OK to accept the options, and then click Apply and OK to return to the main page of the IIS Manager.

9. Click Restart IIS.

Test E-Mail from PHP

Create a test script to see whether you can send e-mail using PHP. Copy the following text and save it as email_test.php at your server root.

Run the file at mydomain.com/email_test.php.

Chủ Nhật, 18 tháng 3, 2012

config Wamp server and IIS run in port 80 in the same time

Setting Both Wamp & IIS on 80 Port (no need of 81 now)

Yes, Finally we are able to use both Wamp and IIS both on 80 port, but you need two Different IP Address on same server, one will server Wamp Server and other will serve IIS.

Old Style and the easy way. Assign different port numbers in IIS and WAMP. They will work without any problem like for IIS Site http://localhost and for Wamp Site http://localhost:81 but what if we don't want to show :81 to customer ? :)

So this is better to use a proper Trick for this.

Step By Step Different IPs and same port:

There are some changes in your registry, which will allow us to use IP address for Wamp server. Many guys try to use this scenario but unfortunately IIS occupy all IP address pointing to 80 port, so even if we will try this we are not able to get wamp page.

In My Case

10.10.10.31 is for http://domain0.com on IIS

10.10.10.32 is for http://domain1.com on IIS

10.10.10.33 is for http://domain2.com on Wamp

Now Adding IP Address to server:

1.Open Network Connection and open Internet Protocol TCP/IP Properties & add manual IP, gateway, and DNS.

image

2. Click Advance.

3. In IP Setting tree and IP Address Click Add

image

4. add all other IP Addresses one by one

image

image

5. Now Click Ok, 3 times :) and then close.

Now when you IP Addresses are added, you need to trick with IIS (using registry). I am not describing here how to assigning different IP Addresses to different website in IIS.

Registry Setting:

Step1. Stop the HTTP service

net stop http in command prompt.

If this command prompts any question about stopping some services, say yes.

Step2. Edit the registry. (You better backup the registry before playing around with it ;))

i. Click Start, click Run, type regedit, and then click OK.

ii. In Registry Editor, locate the following registry subkey:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters\ListenOnlyList

If you don’t find this, no harm. Create one multi-string value in the same name.

iii. Make sure it has only the IP addresses that you want your IIS to listen. In my case, 10.10.10.31 & 10.10.10.32.

One IP address per line.

image

image

Guess what? IIS doesn’t know about 10.10.10.33 anymore. :)

Step3. Start the HTTP Service.

net start http in command prompt.

You have to start couple of services in MMC as well. (HTTP SSL and World Wide Web Publishing Service)

Now, you can run both the web servers together on same port number. Of course, different IP addresses.

10.10.10.31:80 is IIS Website

10.10.10.32:80 is also IIS Website

10.10.10.33:80 is WAMP website.

In fact, 10.10.10.33 is sole property of WAMP now. IIS can’t use this IP address with any port number.

That's All, Good Luck!