Difference between revisions of "Email in Scripts"

From Hostek.com Wiki
Jump to: navigation, search
(ASP Email Sample)
(.NET Email Sample)
Line 56: Line 56:
  
 
==.NET Email Sample==
 
==.NET Email Sample==
 +
 +
 +
=== In Code ===
 +
 +
  MailMessage message = new MailMessage("from@email.address","to@email.address");
 +
  message.Subject = "subject"
 +
  message.Body = "body"
 +
  SmtpClient client = new SmtpClient();
 +
  client.Send(message);
 +
 +
=== In web.config ===
 +
  <system.net>
 +
      <mailSettings>
 +
        <smtp deliveryMethod="Network">
 +
            <network host="smtpmailer.hostek.net" port="25" />
 +
        </smtp>
 +
      </mailSettings>
 +
  </system.net>
 +
 
==ColdFusion Email Sample==
 
==ColdFusion Email Sample==
 
==PHP Email Sample==
 
==PHP Email Sample==

Revision as of 17:20, 22 December 2012

Sending Email via Scripts

To send email via code or scripts (ie web pages) you can use either the built in SMTP host smtpmailer.hostek.net which doesn't require a username/password (only from the server) or you can authenticate using your email account, which does require the username and password too.


ASP Email Sample

Here is a sample using CDOSYS to send email from ASP pages. CDOSYS replaces CDONTS on Windows 2003 servers and after.

NOTE: We suggest using CDOSYS for all ASP email applications.

<%
Dim objCDOConf
Set objCDOConf = Server.CreateObject ("CDO.Configuration")

' ** SET AND UPDATE FIELDS PROPERTIES **
With objCDOConf
' ** OUT GOING SMTP SERVER **

' ** SMTP PORT **
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpmailer.hostek.net"

' ** CDO PORT **
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

' ** TIMEOUT **
.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

.Fields.Update
End With


Dim iMsg
set iMsg = CreateObject("CDO.Message")

' ** UPDATE THE CDOSYS CONFIGURATION **
Set iMsg.Configuration = objCDOConf



' apply settings to the message
With iMsg
  .To = "test@some_address.com"
  .From = "test@your_domain.com"
  .Subject = "This is a subject"
  .TextBody = "This is the body of the email."
  .Send
End With

' cleanup of variables
Set iMsg = Nothing
%>

.NET Email Sample

In Code

 MailMessage message = new MailMessage("from@email.address","to@email.address");
 message.Subject = "subject"
 message.Body = "body"
 SmtpClient client = new SmtpClient();
 client.Send(message);

In web.config

  <system.net>
     <mailSettings>
        <smtp deliveryMethod="Network">
           <network host="smtpmailer.hostek.net" port="25" />
        </smtp>
     </mailSettings>
  </system.net>

ColdFusion Email Sample

PHP Email Sample