Sending Emails    Getting-started

Is there any web application which does not send emails? Probably yes, but there are only few of them out there. Because email is so crucial we had the focus to provide an email wrapper class which lets you send emails without headache. Even with one line if you like :)

Forget the problem of choosing the right email component (installing & configuring it). ajaxed does that for you. It checks which components are installed on the server and uses the "best" one. Please refer to the API to see which components are currently supported. As this page been written Jmail, ASPEmail and CDOSYS was supported. Great, so lets send out our first email:


<!--#include virtual="/ajaxed/ajaxed.asp"-->
<!--#include virtual="/ajaxed/class_email/email.asp"-->
<%
set page = new AjaxedPage
page.draw()

sub main()
  with new Email
    .addRecipient "to", "some@email.com", "Some recipient"
    .sendersName = "ajaxed.org"
    .sendersEmail = "ajaxed@yourserver.com"
    .mailserver = "smtp.yourserver.com"
    .subject = "Hello world!"
    .body = "ajaxed says hello"
    .send()
  end with
end sub
%>


This snippet quite explains itself. We load the Email class with the include statement first. After that we are able to use the class. The property names and methods say the rest. But thats a bit lot of code if we want to send emails rapidly within our app. For that reason we can override all the common settings of Email in our config.asp (afterwards they are used for every new email instance):


<%
AJAXED_EMAIL_SENDER = "ajaxed@yourserver.com"
AJAXED_EMAIL_SENDER_NAME = "ajaxed.org"
AJAXED_MAILSERVER = "smtp.yourserver.com"
AJAXED_EMAIL_DISPATCH = false
%>

Clear? The only one which might be unclear is AJAXED_EMAIL_DISPATCH. This setting prevents the email from actually being dispatched. The whole process of email sending is simulated but in the end the email is not sent. Thats useful during the development process. The emails seem to be sent, but acutally they are not :) You can see them in your log though. Anyway, now we can send an email with only that code:


<!--#include virtual="/ajaxed/ajaxed.asp"-->
<!--#include virtual="/ajaxed/class_email/email.asp"-->
<%
set page = new AjaxedPage
page.draw()

sub main()
  with new Email
    .addRecipient "to", "some@email.com", "Some recipient"
    .subject = "Hello world!"
    .body = "ajaxed says hello"
    if not .send() then str.write("Could not send: " & .errorMsg)
  end with
end sub
%>

The send() method returns true if mailing was successful. Thus in this case we demonstrated even some error handling ;)

Recommended Settings during development

When developing a web application we recommend you to make use of one of our email DEV features (don't forget to turn them off when going live):

Posted in Getting-started 5801 days ago

Version 2.1.1 Released4132 days ago