Thursday, July 31, 2008

Send mails from a Remote host in Classic ASP

Situation: Your IIS is sitting in a machine A and Webmail is in a remote place say Machine B. To do send the mail from Classic ASP files inside the IIS, go with the below given method. Remember, the From Email id has to be a valid id and it's User Name and Password should be mentioned it the below given code.


Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM


Function SendMailNow(sFromEmail, sToEmail,sCcEmail, sSubject, sText)

Set myMail=CreateObject("CDO.Message")
myMail.Subject = sSubject
myMail.From = sFromEmail
myMail.To = sToEmail
myMail.cc = sCcEmail
myMail.HTMLBody = sText
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "202.151.190.XX"

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

'Your UserID on the SMTP server ONLY A VALID USER NAME, IT SHOULD EXIST
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"

'Your password on the SMTP server PASSWORD OF AN EXISTING USER NAME IN THAT REMORT MACHINE
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

'Server port (typically 25)
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'Use SSL for the connection (False or True)
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

myMail.Configuration.Fields.Update

myMail.Send

Response.Write("Mail Sent")
Response.End



End Function

Send Mail from a Remote Host in Classic ASP

Situation: Your IIS is sitting in a machine A and Webmail is in a remote place say Machine B. To do send the mail from Classic ASP files inside the IIS, go with the below given method. Remember, the From Email id has to be a valid id and it's User Name and Password should be mentioned it the below given code.



<%
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM


Function SendMailNow(sFromEmail, sToEmail,sCcEmail, sSubject, sText)

Set myMail=CreateObject("CDO.Message")
myMail.Subject = sSubject
myMail.From = sFromEmail
myMail.To = sToEmail
myMail.cc = sCcEmail
myMail.HTMLBody = sText
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "202.151.190.XX"

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

'Your UserID on the SMTP server ONLY A VALID USER NAME, IT SHOULD EXIST
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"

'Your password on the SMTP server PASSWORD OF AN EXISTING USER NAME IN THAT REMORT MACHINE
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

'Server port (typically 25)
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'Use SSL for the connection (False or True)
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

myMail.Configuration.Fields.Update

myMail.Send

Response.Write("Mail Sent")
Response.End



End Function

%>

Friday, July 4, 2008

Binding DropDown List from Web.Config

Add the keys in the Web.Config under App Settings as given below.






Call up the Method BindColors() from Page Load by passing the DropDown Object

using System.Configuration; // This name space to be added in the page.
// If this is not available, Add Reference to the System.Configuration dll// from the .Net Tab by right clicking on the website and adding.
BindColors(DrpColor);

private void BindColors(DropDownList oDrp)
{
String ColorTexts = ConfigurationManager.AppSettings["ColorText"];
String ColorValues = ConfigurationManager.AppSettings["ColorValue"];

string[] ColorText = ColorTexts.Split(';');
string[] ColorValue = ColorValues.Split(';');

ListItemCollection oCollection = new ListItemCollection();

for (int i = 0; i < ColorText.Length; i++)
{
ListItem oItem = new ListItem();
oItem.Value = ColorValue[i].ToString();
oItem.Text = ColorText[i];
oCollection.Add(oItem);
}

oDrp.DataTextField = "Text";
oDrp.DataValueField = "Value";
oDrp.DataSource = oCollection;
oDrp.DataBind();
}
Dropdown’s Text and Values are bound.