NAnt SDK Documentation - v0.92 |

# MailTask Class

Sends an SMTP message.

For a list of all members of this type, see MailTask Members.

System.Object
NAnt.Core.Element
NAnt.Core.Task
NAnt.Core.Tasks.MailTask

[Visual Basic]
<TaskName(Name:="mail")>
Public Class MailTask
Inherits Task
[C#]
[TaskName(Name="mail")]
public class MailTask : Task

#### Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

#### Remarks

Text and text files to include in the message body may be specified as well as binary attachments.

#### Example

Sends an email from `nant@sourceforge.net` to three recipients with a subject about the attachments. The body of the message will be the combined contents of all `.txt` files in the base directory. All zip files in the base directory will be included as attachments. The message will be sent using the `smtpserver.anywhere.com` SMTP server.

    <mail
        from="nant@sourceforge.net"
        tolist="recipient1@sourceforge.net"
        cclist="recipient2@sourceforge.net"
        bcclist="recipient3@sourceforge.net"
        subject="Msg 7: With attachments"
        mailhost="smtpserver.anywhere.com">
        <files>
            <include name="*.txt" />
        </files>
        <attachments>
            <include name="*.zip" />
        </attachments>
    </mail>

Sends an email from a gmail account to multiple recipients. This example illustrates how to add a recipient's name to an email address.

    <mail
        from="+xxxx+@gmail.com"
        tolist="(Rep A) recipient1@sourceforge.net;(Rep B) recipient2@sourceforge.net"
        subject="Sample Email"
        mailhost="smtp.gmail.com"
        mailport="465"
        ssl="true"
        user="+xxxx+@gmail.com"
        password="p@ssw0rd!"
        message="Email from NAnt" />

Email addresses in any of the lists (to, cc, bcc, from) can be in one of the five listed formats below.

- Full Name <address@abcxyz.com>
- <address@abcxyz.com> Full Name
- (Full Name) address@abcxyz.com
- address@abcxyz.com (Full Name)
- address@abcxyz.com

Remember to use &gt; and &lt; XML entities for the angle brackets.

#### Requirements

Namespace: NAnt.Core.Tasks

Assembly: NAnt.Core (in NAnt.Core.dll)

#### See Also

MailTask Members | NAnt.Core.Tasks Namespace