go to ISQsolutions.com | Contact Us

 
Q10244 - FAQ: How do I send emails from my Web application?

- Introduction.

At ISQsolutions it is required that all email messaging have to be authenticated, any attempt to send anonymous email will fail. To send email from your website you will need to configure your scripts to authenticate against your designated SMTP server (usually smtp.yourdomain.com or smtp.websoon.com) with one of your existent email accounts at ISQsolutions mail servers.

- Sending emails in ASP.NET 2.0

// using System.Net.Mail;
// using System.Net;

SmtpClient smtpClient = new SmtpClient("smtp.domainHosted.com");

smtpClient.Credentials = new NetworkCredential("user1@domainHosted.com", "passwordHere");

MailMessage message = new MailMessage();

message.From = new MailAddress(user1@domainHosted.com);
message.To.Add(new MailAddress(nick@example.com));
message.To.Add(new MailAddress(ben@example.com));

message.Subject = "This is my subject";
message.Body = "This is the content";

smtpClient.Send(message);


- Sending mail from ASP via CDO object. ( What happened to CDONTS ? )

With the introduction of Windows Server 2003, Microsoft dropped support for CDONTS. Therefore, applications that use CDONTS do not function on Windows Server 2003, furthermore CDONTS does not provide the means to send email via authenticated SMTP.

<%
Set myMail=Server.CreateObject("CDO.Message")

myMail.Subject="Sending email with CDO"
myMail.From="me@example.com"
myMail.To="you@example.com"

myMail.TextBody="This is a message."

myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.YourDomain.com"
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25

'Authentication
myMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
myMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Account@YourDomain.com"
myMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Password"
myMail.Configuration.Fields.Update

myMail.Send
%>

These examples may not work for you without certain modifications.
The purpose of the examples is to give you a general idea on the topic.

References:
Microsoft Windows Server 2003 does not install CDONTS : http://support.microsoft.com/default.aspx?scid=kb;en-us;315197



- Sending mail from ASP with Persits ASPEmail object.

Consult the excellent documentation that Persits have put together at : http://www.aspemail.com/manual.html
Here is a short example:
<%

Set objMail = Server.CreateObject("Persits.MailSender")

objMail.Host = "smtp.DomainHosted.com"
objMail.Username = "account@DomainHosted.com"
objMail.Password = "Password"


objMail.From = "me@example.com" 'from me
objMail.AddAddress ("you@example.com") 'to you

objMail.Subject = "Hello you."
objMail.body = "This is a test message."

On Error Resume Next
objMail.Send
If Err <> 0 Then
Response.Write "An error occurred: " & Err.Description
End If

objMail = Nothing
%>

These examples may not work for you without certain modifications.
The purpose of the examples is to give you a general idea on the topic.


- Sending mail from ASP.NET.


Here is a C# version.

// using System.Web.Mail;

MailMessage eMail = new MailMessage();

eMail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
eMail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "account@domainHosted.com";
eMail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "password";

eMail.To = "someone@yahoo.com"; // Recipients
eMail.From = "somebody@yahoo.com";
eMail.Subject = "This is the subject line";
eMail.Body = "Test Message";

SmtpMail.SmtpServer = "smtp.domainHosted.com";
SmtpMail.Send(eMail);

And a VisualBasic version

Dim eMail = new MailMessage()

eMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

eMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "account@domainHosted.com"
eMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"


eMail.To = "someone@yahoo.com"
eMail.From = "somebody@yahoo.com"
eMail.Subject = "This is the subject line"
eMail.Body = "Test Message"

SmtpMail.SmtpServer = "smtp.domainHosted.com"
SmtpMail.Send(eMail)


These examples may not work for you without certain modifications.
The purpose of the examples is to give you a general idea on the topic.

- Sending mail from PHP.

This sample uses the Pear Mail package. The package is already in the INCLUDE path.
http://pear.php.net/package/Mail

include_once("Mail.php");

$recipients = 'mail_to@domain.mail';

$headers["From"] = 'mail_from@domain.mail';
$headers["To"] = 'mail_to@domain.mail';
$headers["Subject"] = "Test message";

$body = "TEST MESSAGE!!!";

$params["host"] = 'smtp.domainHosted.com';
$params["port"] = "25";
$params["auth"] = true;
$params["username"] = 'account@domainHosted.com';
$params["password"] = "password";

// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory("smtp", $params);

$mail_object->send($recipients, $headers, $body);

echo "Email sent."
?>

These examples may not work for you without certain modifications.
The purpose of the examples is to give you a general idea on the topic.


- Setting up a Form to Mail script.

To set-up a very easy form to mail script you may download the following script. To configure it follow the instructions inside the formmail.asp file.

http://support.isqsolutions.com/downloads/formmail.zip

Related Articles
Q10046 - FAQ: What are my incoming and outgoing email servers?

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
It worked! Approved: 9/17/2009 10:52:00 PM
I think if, the article doesnt have "These examples may not work for you without certain modifications. The purpose of the examples is to give you a general idea on the topic." And instead we could see a complete example it will be rating as 10, Thanks any ways Approved: 1/3/2006 2:38:00 PM
In Just one Word I describe this article "Great" Dirgham@Saudi-Car.com Approved: 11/23/2005 1:25:00 AM
Created on 8/9/2005 4:42:00 PM.
Last Modified on 10/1/2008 2:12:00 PM.
Last Modified by ISQ Solutions Inc.
Article has been viewed 46801 times.
Rated 4 out of 10 based on 83 votes.
Print Article