Difference between revisions of "Email in Scripts"
From Hostek.com Wiki
(→ASP Email Sample) |
(→ASP Email Sample) |
||
| Line 16: | Line 16: | ||
' ** SET AND UPDATE FIELDS PROPERTIES ** | ' ** SET AND UPDATE FIELDS PROPERTIES ** | ||
With objCDOConf | With objCDOConf | ||
| − | ' ** | + | ' ** OUTGOING SMTP SERVER ** |
| − | ' ** SMTP | + | ' ** SMTP SERVER ** |
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpmailer.hostek.net" | .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpmailer.hostek.net" | ||
| − | ' ** | + | ' ** SMTP PORT ** |
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 | .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 | ||
| Line 38: | Line 38: | ||
' ** UPDATE THE CDOSYS CONFIGURATION ** | ' ** UPDATE THE CDOSYS CONFIGURATION ** | ||
Set iMsg.Configuration = objCDOConf | Set iMsg.Configuration = objCDOConf | ||
| − | |||
Revision as of 14:38, 23 September 2014
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.
Contents
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
' ** OUTGOING SMTP SERVER **
' ** SMTP SERVER **
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpmailer.hostek.net"
' ** SMTP PORT **
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
' ** TIMEOUT **
.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>