Index: source-builder/defaults.mc
===================================================================
--- source-builder/defaults.mc	(revision dfdc129a08a01c9a9e3500574020219be653d504)
+++ source-builder/defaults.mc	(revision 97a685fae36578912e02b08c941b4eac9f21bd39)
@@ -248,2 +248,6 @@
 _forced_static:     none,         none, '-Xlinker -Bstatic ${LIBS_STATIC} -Xlinker -Bdynamic'
 __xz:                exe,     required, '/usr/bin/xz'
+
+# Mail Support
+_mail_smtp_host:   none,         none, 'localhost'
+_mail_tools_to:    none,         none, 'rtems-tooltestresults@rtems.org'
Index: source-builder/sb/git.py
===================================================================
--- source-builder/sb/git.py	(revision dfdc129a08a01c9a9e3500574020219be653d504)
+++ source-builder/sb/git.py	(revision 97a685fae36578912e02b08c941b4eac9f21bd39)
@@ -149,4 +149,24 @@
         return _remotes
 
+    def email(self):
+        _email = None
+        _name = None
+        ec, output = self._run(['config', '--list'])
+        if ec == 0:
+            for l in output.split('\n'):
+                if l.startswith('user.email'):
+                    ls = l.split('=')
+                    if len(ls) >= 2:
+                        _email = ls[1]
+                elif l.startswith('user.name'):
+                    ls = l.split('=')
+                    if len(ls) >= 2:
+                        _name = ls[1]
+        if _email is not None:
+            if _name is not None:
+                _email = '%s <%s>' % (_name, _email)
+            return _email
+        return None
+
     def head(self):
         hash = ''
@@ -167,3 +187,4 @@
     print g.clean()
     print g.remotes()
+    print g.email()
     print g.head()
Index: source-builder/sb/mailer.py
===================================================================
--- source-builder/sb/mailer.py	(revision 97a685fae36578912e02b08c941b4eac9f21bd39)
+++ source-builder/sb/mailer.py	(revision 97a685fae36578912e02b08c941b4eac9f21bd39)
@@ -0,0 +1,109 @@
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2013 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+#
+# Manage emailing results or reports.
+#
+
+import os
+import smtplib
+import socket
+
+import error
+import options
+import path
+
+def append_options(opts):
+    opts['--mail'] = 'Send email report or results.'
+    opts['--smtp-host'] = 'SMTP host to send via.'
+    opts['--mail-to'] = 'Email address to send the email too.'
+    opts['--mail-from'] = 'Email address the report is from.'
+
+class mail:
+    def __init__(self, opts):
+        self.opts = opts
+
+    def from_address(self):
+
+        def _clean(l):
+            if '#' in l:
+                l = l[:l.index('#')]
+            if '\r' in l:
+                l = l[:l.index('r')]
+            if '\n' in l:
+                l = l[:l.index('\n')]
+            return l.strip()
+
+        addr = self.opts.get_arg('--mail-from')
+        if addr is not None:
+            return addr[1]
+        mailrc = None
+        if 'MAILRC' in os.environ:
+            mailrc = os.environ['MAILRC']
+        if mailrc is None and 'HOME' in os.environ:
+            mailrc = path.join(os.environ['HOME'], '.mailrc')
+        if mailrc is not None and path.exists(mailrc):
+            # set from="Joe Blow <joe@blow.org>"
+            try:
+                mrc = open(mailrc, 'r')
+                lines = mrc.readlines()
+                mrc.close()
+            except IOError, err:
+                raise error.general('error reading: %s' % (mailrc))
+            for l in lines:
+                l = _clean(l)
+                if 'from' in l:
+                    fa = l[l.index('from') + len('from'):]
+                    if '=' in fa:
+                        addr = fa[fa.index('=') + 1:].replace('"', ' ').strip()
+            if addr is not None:
+                return addr
+        addr = self.opts.defaults.get_value('%{_sbgit_mail}')
+        return addr
+
+    def smtp_host(self):
+        host = self.opts.get_arg('--smtp-host')
+        if host is not None:
+            return host[1]
+        host = self.opts.defaults.get_value('%{_mail_smtp_host}')
+        if host is not None:
+            return host
+        return 'localhost'
+
+    def send(self, to_addr, subject, body):
+        from_addr = self.from_address()
+        msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % \
+            (from_addr, to_addr, subject) + body
+        try:
+            s = smtplib.SMTP(self.smtp_host())
+            s.sendmail(from_addr, [to_addr], msg)
+        except smtplib.SMTPException, se:
+            raise error.general('sending mail: %s' % (str(se)))
+        except socket.error, se:
+            raise error.general('sending mail: %s' % (str(se)))
+
+if __name__ == '__main__':
+    import sys
+    optargs = {}
+    append_options(optargs)
+    opts = options.load(sys.argv, optargs = optargs, defaults = 'defaults.mc')
+    m = mail(opts)
+    print 'From: %s' % (m.from_address())
+    print 'SMTP Host: %s' % (m.smtp_host())
+    m.send(m.from_address(), 'Test mailer.py', 'This is a test')
Index: source-builder/sb/setbuilder.py
===================================================================
--- source-builder/sb/setbuilder.py	(revision dfdc129a08a01c9a9e3500574020219be653d504)
+++ source-builder/sb/setbuilder.py	(revision 97a685fae36578912e02b08c941b4eac9f21bd39)
@@ -36,4 +36,5 @@
     import error
     import log
+    import mailer
     import options
     import path
@@ -60,13 +61,13 @@
         self.bset = bset
         self.bset_pkg = '%s-%s-set' % (self.macros.expand('%{_target}'), self.bset)
-        self.email_report = ''
-
-    def write_email_report(self, text, prepend = False):
+        self.mail_report = ''
+
+    def write_mail_report(self, text, prepend = False):
         if len(text) == 0 or text[-1] != '\n' or text[-1] != '\r':
             text += os.linesep
         if prepend:
-            self.email_report = text + self.email_report
+            self.mail_report = text + self.mail_report
         else:
-            self.email_report += text
+            self.mail_report += text
 
     def copy(self, src, dst):
@@ -85,5 +86,5 @@
 
     def report(self, _config, _build):
-        if not _build.opts.get_arg('--no-report') and not _build.opts.get_arg('--no-email'):
+        if not _build.opts.get_arg('--no-report') and _build.opts.get_arg('--mail'):
             format = _build.opts.get_arg('--report-format')
             if format is None:
@@ -119,10 +120,10 @@
                     r.write(outname)
                 del r
-            if not _build.opts.get_arg('--no-email'):
+            if _build.opts.get_arg('--mail'):
                 r = reports.report('text', self.configs, _build.opts, _build.macros)
                 r.setup()
                 r.introduction(_build.config.file_name())
                 r.config(_build.config, _build.opts, _build.macros)
-                self.email_report += r.out
+                self.mail_report += r.out
                 del r
 
@@ -276,7 +277,9 @@
         log.notice('Build Set: %s' % (self.bset))
 
-        if not self.opts.get_arg('--no-email'):
-            email_report_header = \
-                'Build Set: %s (%s)' % (self.bset, datetime.datetime.now().ctime())
+        if self.opts.get_arg('--mail'):
+            mail_report_subject = \
+                'Build Set: %s %s (%s)' % (self.bset,
+                                           self.macros.expand('%{_host}'),
+                                           datetime.datetime.now().ctime())
 
         configs = self.load()
@@ -318,5 +321,5 @@
                         raise error.general('invalid config type: %s' % (configs[s]))
                 except error.general, gerr:
-                    self.write_email_report(str(gerr))
+                    self.write_mail_report(str(gerr))
                     if self.opts.keep_going():
                         print gerr
@@ -345,10 +348,19 @@
         os.environ['PATH'] = current_path
 
-        log.notice('Build Set: Time %s' % (str(end - start)))
-
-        if not self.opts.get_arg('--no-email'):
-            self.write_email_report('', True)
-            self.write_email_report('  Build Time %s' % (str(end - start)), True)
-            self.write_email_report(email_report_header, True)
+        build_time = str(end - start)
+
+        if self.opts.get_arg('--mail'):
+            to_addr = self.opts.get_arg('--mail-to')
+            if to_addr is not None:
+                to_addr = to_addr[1]
+            else:
+                to_addr = self.macros.expand('%{_mail_tools_to}')
+            log.notice('Mailing report: %s' % (to_addr))
+            self.write_mail_report('Build Time %s' % (build_time), True)
+            m = mailer.mail(self.opts)
+            if not self.opts.dry_run():
+                m.send(to_addr, mail_report_subject, self.mail_report)
+
+        log.notice('Build Set: Time %s' % (build_time))
 
 def list_bset_cfg_files(opts, configs):
@@ -375,9 +387,6 @@
                     '--pkg-tar-files': 'Create package tar files',
                     '--no-report':     'Do not create a package report.',
-                    '--report-format': 'The report format (text, html, asciidoc).',
-                    '--no-email':      'Do not send an email report.',
-                    '--smtp-host':     'SMTP host to send via.',
-                    '--email-to':      'Email address to send the email too.',
-                    '--email-from':    'Email address the report is from.' }
+                    '--report-format': 'The report format (text, html, asciidoc).' }
+        mailer.append_options(optargs)
         opts = options.load(sys.argv, optargs)
         log.notice('RTEMS Source Builder - Set Builder, v%s' % (version.str()))
