Scot's Scripts FAQs and Module Support

If you don't find the answers here contact us.
Documentation and support for our Miva modules is found here. If you can't find the answer you're looking for contact us and we'll add the information.

Miva Script 101 / MvSMTP Usage and Headers

MvSMTP Usage and Headers

MvSMTP

The MvSMTP mivascript tag (Mv - Simple - Mail - Transfer - Protocol) is what you use to send out an email. Basic usage is very easy. You have an email address the message is going to, an email address it's being sent from, a subject, and a message. The easiest way to use MvSMTP would be something like the following. Note that mailhost could be different in your setup (but usually it's not.)

<MvSMTP 
  FROM = "some_email_address@some_domain.com"
  TO = "some_email_address@some_domain.com"
  SUBJECT = "This is your subject."
  MAILHOST = "localhost"> 
  Hi, this is an email message.
</MvSMTP>

The MvSMTP tag has quite a few other options if you want to get more advanced.

<MvSMTP 
  FROM = "string: { expression } | string: { expression }"
  TO = "string: { expression } | literal"
  CC = "string: { expression } | literal"
  SUBJECT = "string: { expression } | literal"
  FLAGS = "string: { expression } | literal"
  MAILHOST = "string: { expression } | literal"
  PORT = "string: { number } | literal number"
  USERNAME = "string: { expression } | literal"
  PASSWORD = "string: { expression } | literal"> 
</MvSMTP>
Attribute Description
FROM Required. A valid email address (or comma separated list of email addresses) that the email is being sent from
TO Required. A valid recipient email address or comma separated list of email addresses.
MAILHOST Required. This is the SMTP host of your server. Most of the time on Miva setups it will be localhost. If you are running Miva Merchant, you can check the domain settings for the mailhost to verify (or just check your host's support/FAQ pages.)
CC A comma separated list of email addresses the message should also go out to. Do not use this tag in a mailing list situation, use software designed for mailing lists, such as Scot's Mailing List so you don't shut your SMTP server down through too much outgoing data.
SUBJECT The basic subject of the message, required.
FLAGS Comma separated list of one or more of the following flags:
  • tls -- Specifies that implicit TLS/SSL should be used for transport encryption
  • starttls -- Specifies that the SMTP STARTTLS command should be used for transport encryption
  • noheaders -- Turns off the default automatic headers Date, From, To, CC, X-Mailer and Subject. Use this flag if you want to create your own headers to use real names for example.
PORT Use this to enter a custom SMTP port. Miva Mia and Miva Empressa default to port 25 but that port is blocked on many servers. This feature is new for 2013, and it's about time.
USERNAME SMTP login username if necessary
PASSWORD SMTP login password if necessary.

Common SMTP Headers

You don't need to know how and why all of this works, but if you are curious and want some light reading, check out these two Request for Comments documents.

Header Description
From: The eMail address, and optionally the name of the author(s). In many eMail clients not changeable except through changing account settings.
To: The eMail address(es), and optionally name(s) of the message's recipient(s). Indicates primary recipients (multiple allowed), for secondary recipients see Cc: and Bcc: below.
Subject: A brief summary of the topic of the message. Certain abbreviations are commonly used in the subject, including "RE:" and "FW:".
Date: The local time and date when the message was written. Like the From: field, many email clients fill this in automatically when sending. The recipient's client may then display the time in the format and time zone local to him/her.
Message-ID: Also an automatically generated field; used to prevent multiple delivery and for reference in In-Reply-To: (see below).
Bcc: Blind Carbon Copy; addresses added to the SMTP delivery list but not (usually) listed in the message data, remaining invisible to other recipients.
Cc: Carbon copy; Many eMail clients will mark eMail in your inbox differently depending on whether you are in the To: or Cc: list.
Content-Type: Information about how the message is to be displayed, usually a MIME type.
In-Reply-To: Message-ID of the message that this is a reply to. Used to link related messages together.
Precedence: Commonly with values "bulk", "junk", or "list"; used to indicate that automated "vacation" or "out of office" responses should not be returned for this mail, e.g. to prevent vacation notices from being sent to all other subscribers of a mailinglist.
Received: Tracking information generated by mail servers that have previously handled a message, in reverse order (last handler first).
References: Message-ID of the message that this is a reply to, and the message-id of the message the previous was reply a reply to, etc
Reply-To: Address that should be used to reply to the message.
Sender: Address of the actual sender acting on behalf of the author listed in the From: field (secretary, list manager, etc.).
Return-Path: When the delivery SMTP server makes the "final delivery" of a message, it inserts a return-path line at the beginning of the mail data. Thisuse of return-path is required; mail systems MUST support it. The return-path line preserves the information in the from the MAIL command.
Error-To: Indicates where error messages should be sent. In the absence of this line, they go to the Sender:, and absent that, the From: address.
X-* No standard header field will ever begin with the characters "X-", so application developers are free to use them for their own purposes.

MvSMTP Custom Headers

It's kind of silly that the MvSMTP tag doesn't include attributes such as To-Name and From-Name because if it did, we'd save all sorts of coding time. But it doesn't so we have to create headers to use real names which is expected for any email message.

To create custom headers the first thing you do is set the noheaders flag, then you manually create the required headers by displaying them in the message body. Here's an example from Scot's Mailing List source code.

<MIVA STANDARDOUTPUTLEVEL = ""> 
<MvSMTP
  FROM="{ l.from_email }"
  TO="{ l.to_email }"
  USERNAME="{ l.smtpuser }"
  PASSWORD="{ l.smtppass }"
  MAILHOST="{ l.host }"
  PORT="{ l.mailport }"
  FLAGS = "noheaders" >
  <MvEVAL EXPR = "{ l.to }">
  <MvEVAL EXPR = "{ l.from }">
  <MvIF EXPR = "{ l.reply }">
    <MvEVAL EXPR = "{ l.reply }">
  </MvIF>
  <MvEVAL EXPR = "{ l.date }">
  <MvEVAL EXPR = "{ l.subject }">
  <MvEVAL EXPR = "{ l.xheaders }">
  <MvEVAL EXPR = "{ l.message }">
</MvSMTP>

All of the data is set previously in local variables, example values below. Note that each of the header lines such as l.from, l.reply, l.date, etc, all have a carriage-return/line-feed at the end, added behind the scenes. This CR/LF is required and the emails will be glitchy if you don't do it this way. Here's how you create a CR/LF variable in Miva Script.

<MvASSIGN NAME="l.cr" VALUE="{ asciichar(13) $ asciichar(10) }">
Variable Example Value
l.from_email sender_email@domain.com
l.to_email recipient_email@domain.com
l.username some_login
l.password some_password
l.host localhost
l.port 25
l.to To: <recipient_email@domain.com> First_Name Last_Name
l.from From: <sender_email@domain.com> First_Name Last_Name
l.reply Reply-To: <reply_email@domain.com> First_Name Last_Name
l.date Tue, 30 Jul 2013 19:32:18 -0700
l.subject This is my email message subject.
l.xheaders extra header information, each line ending with a CR/LF
l.message The body of the message. If you want to send an HTML message or message attachments this part gets a bit complicated. Best thing to do is check out the limited miva merchant source kit for a great example of how to build a MIME email (there are lots of complicated rules involved.)
updated July 30, 2013