The Server.NewMail Object
The Server.NewMail() method
returns an instance of the Mail
object (as CDONTS.NewMail does).
This object can be used to send email through the SMTP server
specified in the The aspisapi.ini
Configuration File.
The differences between the Server.NewMail and CDONTS.NewMail objects are:
-
Value()behaves differently (see below) -
AttachURL()behaves differently (see below) -
Send()returns a value indicating the success of the email transmission -
Body can be only a string
-
SetLocaleIDs is ignored
To send a plain text email without attachments:
Dim Mail Set Mail = Server.NewMail Mail.From = "from@example.com" Mail.To = "to@example.com" Mail.Subject = "This is the subject of the sample email" Mail.Body = "This is the body of the sample email" Mail.Send Set Mail = nothing
To send an HTML email without attachments:
Dim Mail Set Mail = Server.NewMail Mail.From = "from@example.com" Mail.To = "to@example.com" Mail.Subject = "Test mail" Mail.Body = "<html><body><strong>Hello world!</strong></body></html>" Mail.MailFormat = 0 ' MIME Mail.BodyFormat = 0 ' HTML Mail.Send Set Mail = nothing
To send a plain text email with attachments:
Dim Mail
Set Mail = Server.NewMail
Mail.From = "from@example.com"
Mail.To = "to@example.com"
Mail.Subject = "This is the subject of the sample email"
Mail.Body = "This is the body of the sample email"
Mail.AttachFile(Server.MapPath("images/dwebpro_box.gif"))
Mail.MailFormat = 0 ' MIME
Mail.Send
Set Mail = nothing
To send an HTML email with attachments:
Dim Mail
Set Mail = Server.NewMail
Mail.From = "from@example.com"
Mail.To = "to@example.com"
Mail.Subject = "Test mail"
Mail.Body = "<html><body><strong>Hello world!</strong></body></html>"
Mail.AttachFile(Server.MapPath("images/dwebpro_box.gif"))
Mail.MailFormat = 0 ' MIME
Mail.BodyFormat = 0 ' HTML
Mail.Send
Set Mail = nothing
To send an HTML email with embedded attachments:
Dim Mail
Set Mail = Server.NewMail
Mail.From = "from@example.com"
Mail.To = "to@example.com"
Mail.Subject = "Test mail"
Mail.Body = "<html><body><img src='cid:EmbeddedPic'/>"
Mail.Body = Mail.Body & "<strong>Hello world!</strong></body></html>"
Mail.AttachURL Server.MapPath("images/dwebpro_box.gif"), "EmbeddedPic"
Mail.MailFormat = 0 ' MIME
Mail.BodyFormat = 0 ' HTML
Mail.Send
Set Mail = nothing
To use the Value method
(different than CDONTS.NewMail):
Dim Mail
Set Mail = Server.NewMail
Mail.From = "from@example.com"
Mail.To = "to@example.com"
Mail.Subject = "This is the subject of the sample email"
Mail.Body = "This is the body of the sample email"
Mail.Value("Organization", "Your Company")
Mail.Send
Set Mail = nothing
To use the Send() return
value:
Dim Mail
Dim RetVal
Set Mail = Server.NewMail
Mail.From = "from@example.com"
Mail.To = "to@example.com"
Mail.Subject = "This is the subject of the sample email"
Mail.Body = "This is the body of the sample email"
RetVal = Mail.Send
if (RetVal = 0) then
Response.Write("Mail sent successfully!")
elseif (RetVal = 1) then
Response.Write("Socket error (check SMTP server connection)!")
elseif (RetVal = 2) then
Response.Write("Protocol error (check mail properties)!")
else
Response.Write("Unknown error !")
end if
Set Mail = nothing
The following represent write-only properties:
-
From: string;
-
To: string;
-
Bcc: string;
-
CC: string;
-
Importance: integer;
0 = Low
1 = Normal (default)
2 = High
-
Subject: string;
-
Body: string;
-
ContentLocation: string;
-
ContentBase: string;
-
BodyFormat: integer;
0 = HTML
1 = Text (default)
-
MailFormat: integer;
0 = MIME
1 = Text (default)
The following represent read-only properties:
-
Version: string;
The following are the methods:
-
procedure
Value(Item, Value: string); -
procedure
AttachFile(Source: string; optional FileName: string; optional EncodingMethod: integer); -
procedure
AttachURL(Source: string; optional cid: string; optional EncodingMethod: Integer); -
function
Send(From: string; optional To: string; optional Subject: string; optional Body: string; optional Importance: integer): integer;


