Some time ago, I sent a simple JMAIL email code. Today I will make a specific comment on this code, and add two other format codes, and give a few simple examples:
The first is the core code of jmail.smtpmail:
<%
Set jmail = Server.CreateObject("JMAIL.SMTPMail") 'Create a JMAIL object
jmail.silent = true 'JMAIL will not throw exception errors, and the returned values are FALSE and TRUE
jmail.logging = true 'Enable usage logs
jmail.Charset = "GB2312" 'The code of the email text is Simplified Chinese
jmail.ContentType = "text/html" 'The format of the email is HTML
jmail.ServerAddress = "Server Address" 'The server that sends emails
jmail.AddRecipient Email 'The recipient of the email
jmail.SenderName = "SenderName" 'The name of the email sender
jmail.Sender = "Email Address" 'The email address of the email sender
jmail.Priority = 1 'Email emergency program, 1 is the fastest, 5 is the slowest, 3 is the default value
jmail.Subject = "Mail Subject" 'The title of the email
jmail.Body = "Mail Body" 'The content of the email
jmail.AddRecipientBCC Email 'The address of the blind email recipient
jmail.AddRecipientCC Email 'The address of the email copy person
jmail.Execute() 'Execute email sending
jmail.Close 'Close the mail object
%>
w3 Jmail4.3 component has redesigned its internal structure - using Message object instead of the original single object Jmail.smtpmail to send emails. Some methods require authentication (such as 163, yahoo, etc.), which can be solved by the following method:
<%
Set jmail = Server.CreateObject("JMAIL.Message") 'Create an object for sending emails
jmail.silent = true 'Shield exception errors and return FALSE and TRUE values j
mail.logging = true 'Enable mail logging
jmail.Charset = "GB2312" 'The text encoding of the email is the national standard
jmail.ContentType = "text/html" 'The format of the email is HTML format
jmail.AddRecipient Email 'Email recipient's address
jmail.From = "Email From for Sender" 'Sender's E-MAIL address
jmail.MailServerUserName = "UserName of Email" 'Username required to log in to the mail server
jmail.MailServerPassword = "Password of Email" 'Password required to log in to the mail server
jmail.Subject = "Mail Subject" 'The title of the email
jmail.Body = "Mail Body" 'The content of the email
jmail.Prority = 1 'Email emergency program, 1 is the fastest, 5 is the slowest, 3 is the default value
jmail.Send("Server Address") 'Perform email sending (via mail server address)
jmail.Close() 'Close the object
%>
Let’s talk about how to send messages using Microsoft’s own CDONTS component:
<%
Set cdomail = Server.CreateObject("CDONTS.NewMail") 'Create a mail object
cdomail.Subject = "Mail Subject" 'Mail title
cdomail.From = "Sender's Mail" 'Sender's address
cdomail.To = "Email will from" 'Recipient's address
cdomail.Body = "Mail Body" 'The content of the email
cdomail.Send 'Execute send
%>
This method is the simplest to send emails, but it also brings certain problems, that is, few servers will open this service!
When we write programs, we usually say that the code should be modularized, so as to facilitate maintenance and porting. Therefore, I will write this email as a subroutine here, which can be called directly when calling (of course, if you are happy to write it as a function, it is also possible, this mainly depends on personal interest):
<%
'Parameter description
'Subject: Email title
'MailAddress: The address of the sending server, such as smtp.163.com
'Email: Recipient's email address
'Sender: Sender's name
'Content: Email content
'Fromer: sender's email address
Sub SendAction(subject, mailaddress, email, sender, content, fromer)
Set jmail = Server.CreateObject("JMAIL.SMTPMail") 'Create a JMAIL object
jmail.silent = true 'JMAIL will not throw exception errors, and the returned values are FALSE and TRUE
jmail.logging = true 'Enable usage logs
jmail.Charset = "GB2312" 'The code of the email text is Simplified Chinese
jmail.ContentType = "text/html" 'The format of the email is HTML
jmail.ServerAddress = mailaddress 'The server that sends mail
jmail.AddRecipient Email 'The recipient of the email
jmail.SenderName = sender 'The name of the email sender
jmail.Sender = fromer 'The email address of the email sender
jmail.Priority = 1 'Email emergency program, 1 is the fastest, 5 is the slowest, 3 is the default value
jmail.Subject = subject 'The title of the email
jmail.Body = content 'The content of the email
'Since BCC and CC are not used, these two sentences are blocked here. If you need, you can restore them here.
'jmail.AddRecipientBCC Email 'The address of the blind email recipient
'jmail.AddRecipientCC Email 'The address of the email carbon copy
jmail.Execute() 'Execute email sending
jmail.Close 'Close the mail object
End Sub
'Example of calling this Sub
Dim strSubject,strEmail,strMailAdress,strSender,strContent,strFromer
strSubject = "This is a test email sent using JMAIL"
strContent = "JMail component sent test successfully!"
strEmail = " [email protected] "
strFromer = " [email protected] "
strMailAddress = "mail.ubbcn.com"
Call SendAction (strSubject,strMailaddress,strEmail,strSender,strContent,strFromer)
%>
The above is my rough opinion on the code for sending emails. I would like to thank you for your advice!