Repository: swiftmailer/swiftmailer
Branch: master
Commit: 47a449111b9c
Files: 364
Total size: 3.7 MB
Directory structure:
gitextract_gp3ij5u3/
├── .gitattributes
├── .github/
│ ├── ISSUE_TEMPLATE.md
│ ├── PULL_REQUEST_TEMPLATE.md
│ └── workflows/
│ └── tests.yml
├── .gitignore
├── .php_cs.dist
├── CHANGES
├── LICENSE
├── README.md
├── composer.json
├── doc/
│ ├── headers.rst
│ ├── index.rst
│ ├── introduction.rst
│ ├── japanese.rst
│ ├── messages.rst
│ ├── notes/
│ │ ├── CHARSETS
│ │ ├── rfc/
│ │ │ ├── rfc0821.txt
│ │ │ ├── rfc0822.txt
│ │ │ ├── rfc1341.txt
│ │ │ ├── rfc1521.txt
│ │ │ ├── rfc1854.txt
│ │ │ ├── rfc2015.txt
│ │ │ ├── rfc2045.txt
│ │ │ ├── rfc2046.txt
│ │ │ ├── rfc2047.txt
│ │ │ ├── rfc2048.txt
│ │ │ ├── rfc2049.txt
│ │ │ ├── rfc2183.txt
│ │ │ ├── rfc2222.txt
│ │ │ ├── rfc2231.txt
│ │ │ ├── rfc2234.txt
│ │ │ ├── rfc2440.txt
│ │ │ ├── rfc2487.txt
│ │ │ ├── rfc2554.txt
│ │ │ ├── rfc2821.txt
│ │ │ ├── rfc2822.txt
│ │ │ ├── rfc3156.txt
│ │ │ ├── rfc3676.txt
│ │ │ ├── rfc4505.txt
│ │ │ ├── rfc4616.txt
│ │ │ ├── rfc4870.txt
│ │ │ ├── rfc4871.txt
│ │ │ ├── rfc4880.txt
│ │ │ ├── rfc4954.txt
│ │ │ ├── rfc5751.txt
│ │ │ └── whats_where.txt
│ │ ├── rfc5672.txt
│ │ ├── rfc6376.txt
│ │ └── smtp.txt
│ ├── plugins.rst
│ └── sending.rst
├── lib/
│ ├── classes/
│ │ ├── Swift/
│ │ │ ├── AddressEncoder/
│ │ │ │ ├── IdnAddressEncoder.php
│ │ │ │ └── Utf8AddressEncoder.php
│ │ │ ├── AddressEncoder.php
│ │ │ ├── AddressEncoderException.php
│ │ │ ├── Attachment.php
│ │ │ ├── ByteStream/
│ │ │ │ ├── AbstractFilterableInputStream.php
│ │ │ │ ├── ArrayByteStream.php
│ │ │ │ ├── FileByteStream.php
│ │ │ │ └── TemporaryFileByteStream.php
│ │ │ ├── CharacterReader/
│ │ │ │ ├── GenericFixedWidthReader.php
│ │ │ │ ├── UsAsciiReader.php
│ │ │ │ └── Utf8Reader.php
│ │ │ ├── CharacterReader.php
│ │ │ ├── CharacterReaderFactory/
│ │ │ │ └── SimpleCharacterReaderFactory.php
│ │ │ ├── CharacterReaderFactory.php
│ │ │ ├── CharacterStream/
│ │ │ │ ├── ArrayCharacterStream.php
│ │ │ │ └── NgCharacterStream.php
│ │ │ ├── CharacterStream.php
│ │ │ ├── ConfigurableSpool.php
│ │ │ ├── DependencyContainer.php
│ │ │ ├── DependencyException.php
│ │ │ ├── EmbeddedFile.php
│ │ │ ├── Encoder/
│ │ │ │ ├── Base64Encoder.php
│ │ │ │ ├── QpEncoder.php
│ │ │ │ └── Rfc2231Encoder.php
│ │ │ ├── Encoder.php
│ │ │ ├── Events/
│ │ │ │ ├── CommandEvent.php
│ │ │ │ ├── CommandListener.php
│ │ │ │ ├── Event.php
│ │ │ │ ├── EventDispatcher.php
│ │ │ │ ├── EventListener.php
│ │ │ │ ├── EventObject.php
│ │ │ │ ├── ResponseEvent.php
│ │ │ │ ├── ResponseListener.php
│ │ │ │ ├── SendEvent.php
│ │ │ │ ├── SendListener.php
│ │ │ │ ├── SimpleEventDispatcher.php
│ │ │ │ ├── TransportChangeEvent.php
│ │ │ │ ├── TransportChangeListener.php
│ │ │ │ ├── TransportExceptionEvent.php
│ │ │ │ └── TransportExceptionListener.php
│ │ │ ├── FailoverTransport.php
│ │ │ ├── FileSpool.php
│ │ │ ├── FileStream.php
│ │ │ ├── Filterable.php
│ │ │ ├── IdGenerator.php
│ │ │ ├── Image.php
│ │ │ ├── InputByteStream.php
│ │ │ ├── IoException.php
│ │ │ ├── KeyCache/
│ │ │ │ ├── ArrayKeyCache.php
│ │ │ │ ├── DiskKeyCache.php
│ │ │ │ ├── KeyCacheInputStream.php
│ │ │ │ ├── NullKeyCache.php
│ │ │ │ └── SimpleKeyCacheInputStream.php
│ │ │ ├── KeyCache.php
│ │ │ ├── LoadBalancedTransport.php
│ │ │ ├── Mailer/
│ │ │ │ ├── ArrayRecipientIterator.php
│ │ │ │ └── RecipientIterator.php
│ │ │ ├── Mailer.php
│ │ │ ├── MemorySpool.php
│ │ │ ├── Message.php
│ │ │ ├── Mime/
│ │ │ │ ├── Attachment.php
│ │ │ │ ├── CharsetObserver.php
│ │ │ │ ├── ContentEncoder/
│ │ │ │ │ ├── Base64ContentEncoder.php
│ │ │ │ │ ├── NativeQpContentEncoder.php
│ │ │ │ │ ├── NullContentEncoder.php
│ │ │ │ │ ├── PlainContentEncoder.php
│ │ │ │ │ ├── QpContentEncoder.php
│ │ │ │ │ ├── QpContentEncoderProxy.php
│ │ │ │ │ └── RawContentEncoder.php
│ │ │ │ ├── ContentEncoder.php
│ │ │ │ ├── EmbeddedFile.php
│ │ │ │ ├── EncodingObserver.php
│ │ │ │ ├── Header.php
│ │ │ │ ├── HeaderEncoder/
│ │ │ │ │ ├── Base64HeaderEncoder.php
│ │ │ │ │ └── QpHeaderEncoder.php
│ │ │ │ ├── HeaderEncoder.php
│ │ │ │ ├── Headers/
│ │ │ │ │ ├── AbstractHeader.php
│ │ │ │ │ ├── DateHeader.php
│ │ │ │ │ ├── IdentificationHeader.php
│ │ │ │ │ ├── MailboxHeader.php
│ │ │ │ │ ├── OpenDKIMHeader.php
│ │ │ │ │ ├── ParameterizedHeader.php
│ │ │ │ │ ├── PathHeader.php
│ │ │ │ │ └── UnstructuredHeader.php
│ │ │ │ ├── IdGenerator.php
│ │ │ │ ├── MimePart.php
│ │ │ │ ├── SimpleHeaderFactory.php
│ │ │ │ ├── SimpleHeaderSet.php
│ │ │ │ ├── SimpleMessage.php
│ │ │ │ └── SimpleMimeEntity.php
│ │ │ ├── MimePart.php
│ │ │ ├── NullTransport.php
│ │ │ ├── OutputByteStream.php
│ │ │ ├── Plugins/
│ │ │ │ ├── AntiFloodPlugin.php
│ │ │ │ ├── BandwidthMonitorPlugin.php
│ │ │ │ ├── Decorator/
│ │ │ │ │ └── Replacements.php
│ │ │ │ ├── DecoratorPlugin.php
│ │ │ │ ├── ImpersonatePlugin.php
│ │ │ │ ├── Logger.php
│ │ │ │ ├── LoggerPlugin.php
│ │ │ │ ├── Loggers/
│ │ │ │ │ ├── ArrayLogger.php
│ │ │ │ │ └── EchoLogger.php
│ │ │ │ ├── MessageLogger.php
│ │ │ │ ├── Pop/
│ │ │ │ │ ├── Pop3Connection.php
│ │ │ │ │ └── Pop3Exception.php
│ │ │ │ ├── PopBeforeSmtpPlugin.php
│ │ │ │ ├── RedirectingPlugin.php
│ │ │ │ ├── Reporter.php
│ │ │ │ ├── ReporterPlugin.php
│ │ │ │ ├── Reporters/
│ │ │ │ │ ├── HitReporter.php
│ │ │ │ │ └── HtmlReporter.php
│ │ │ │ ├── Sleeper.php
│ │ │ │ ├── ThrottlerPlugin.php
│ │ │ │ └── Timer.php
│ │ │ ├── Preferences.php
│ │ │ ├── ReplacementFilterFactory.php
│ │ │ ├── RfcComplianceException.php
│ │ │ ├── SendmailTransport.php
│ │ │ ├── Signer.php
│ │ │ ├── Signers/
│ │ │ │ ├── BodySigner.php
│ │ │ │ ├── DKIMSigner.php
│ │ │ │ ├── DomainKeySigner.php
│ │ │ │ ├── HeaderSigner.php
│ │ │ │ ├── OpenDKIMSigner.php
│ │ │ │ └── SMimeSigner.php
│ │ │ ├── SmtpTransport.php
│ │ │ ├── Spool.php
│ │ │ ├── SpoolTransport.php
│ │ │ ├── StreamFilter.php
│ │ │ ├── StreamFilters/
│ │ │ │ ├── ByteArrayReplacementFilter.php
│ │ │ │ ├── StringReplacementFilter.php
│ │ │ │ └── StringReplacementFilterFactory.php
│ │ │ ├── SwiftException.php
│ │ │ ├── Transport/
│ │ │ │ ├── AbstractSmtpTransport.php
│ │ │ │ ├── Esmtp/
│ │ │ │ │ ├── Auth/
│ │ │ │ │ │ ├── CramMd5Authenticator.php
│ │ │ │ │ │ ├── LoginAuthenticator.php
│ │ │ │ │ │ ├── NTLMAuthenticator.php
│ │ │ │ │ │ ├── PlainAuthenticator.php
│ │ │ │ │ │ └── XOAuth2Authenticator.php
│ │ │ │ │ ├── AuthHandler.php
│ │ │ │ │ ├── Authenticator.php
│ │ │ │ │ ├── EightBitMimeHandler.php
│ │ │ │ │ └── SmtpUtf8Handler.php
│ │ │ │ ├── EsmtpHandler.php
│ │ │ │ ├── EsmtpTransport.php
│ │ │ │ ├── FailoverTransport.php
│ │ │ │ ├── IoBuffer.php
│ │ │ │ ├── LoadBalancedTransport.php
│ │ │ │ ├── NullTransport.php
│ │ │ │ ├── SendmailTransport.php
│ │ │ │ ├── SmtpAgent.php
│ │ │ │ ├── SpoolTransport.php
│ │ │ │ └── StreamBuffer.php
│ │ │ ├── Transport.php
│ │ │ └── TransportException.php
│ │ └── Swift.php
│ ├── dependency_maps/
│ │ ├── cache_deps.php
│ │ ├── message_deps.php
│ │ ├── mime_deps.php
│ │ └── transport_deps.php
│ ├── mime_types.php
│ ├── preferences.php
│ ├── swift_required.php
│ └── swiftmailer_generate_mimes_config.php
├── phpunit.xml.dist
└── tests/
├── IdenticalBinaryConstraint.php
├── StreamCollector.php
├── SwiftMailerSmokeTestCase.php
├── SwiftMailerTestCase.php
├── _samples/
│ ├── charsets/
│ │ ├── iso-2022-jp/
│ │ │ └── one.txt
│ │ ├── iso-8859-1/
│ │ │ └── one.txt
│ │ └── utf-8/
│ │ ├── one.txt
│ │ ├── three.txt
│ │ └── two.txt
│ ├── dkim/
│ │ ├── dkim.test.priv
│ │ └── dkim.test.pub
│ ├── files/
│ │ └── data.txt
│ └── smime/
│ ├── CA.srl
│ ├── ca.crt
│ ├── ca.key
│ ├── create-cert.sh
│ ├── encrypt.crt
│ ├── encrypt.key
│ ├── encrypt2.crt
│ ├── encrypt2.key
│ ├── intermediate.crt
│ ├── intermediate.key
│ ├── sign.crt
│ ├── sign.key
│ ├── sign2.crt
│ └── sign2.key
├── acceptance/
│ └── Swift/
│ ├── AttachmentAcceptanceTest.php
│ ├── ByteStream/
│ │ └── FileByteStreamAcceptanceTest.php
│ ├── CharacterReaderFactory/
│ │ └── SimpleCharacterReaderFactoryAcceptanceTest.php
│ ├── DependencyContainerAcceptanceTest.php
│ ├── EmbeddedFileAcceptanceTest.php
│ ├── Encoder/
│ │ ├── Base64EncoderAcceptanceTest.php
│ │ ├── QpEncoderAcceptanceTest.php
│ │ └── Rfc2231EncoderAcceptanceTest.php
│ ├── KeyCache/
│ │ ├── ArrayKeyCacheAcceptanceTest.php
│ │ └── DiskKeyCacheAcceptanceTest.php
│ ├── MessageAcceptanceTest.php
│ ├── Mime/
│ │ ├── AttachmentAcceptanceTest.php
│ │ ├── ContentEncoder/
│ │ │ ├── Base64ContentEncoderAcceptanceTest.php
│ │ │ ├── NativeQpContentEncoderAcceptanceTest.php
│ │ │ ├── PlainContentEncoderAcceptanceTest.php
│ │ │ └── QpContentEncoderAcceptanceTest.php
│ │ ├── EmbeddedFileAcceptanceTest.php
│ │ ├── HeaderEncoder/
│ │ │ └── Base64HeaderEncoderAcceptanceTest.php
│ │ ├── MimePartAcceptanceTest.php
│ │ └── SimpleMessageAcceptanceTest.php
│ ├── MimePartAcceptanceTest.php
│ └── Transport/
│ └── StreamBuffer/
│ ├── AbstractStreamBufferAcceptanceTest.php
│ ├── BasicSocketAcceptanceTest.php
│ ├── ProcessAcceptanceTest.php
│ ├── SocketTimeoutTest.php
│ ├── SslSocketAcceptanceTest.php
│ └── TlsSocketAcceptanceTest.php
├── acceptance.conf.php.default
├── bootstrap.php
├── bug/
│ └── Swift/
│ ├── Bug111Test.php
│ ├── Bug118Test.php
│ ├── Bug206Test.php
│ ├── Bug274Test.php
│ ├── Bug34Test.php
│ ├── Bug35Test.php
│ ├── Bug38Test.php
│ ├── Bug518Test.php
│ ├── Bug51Test.php
│ ├── Bug534Test.php
│ ├── Bug650Test.php
│ ├── Bug71Test.php
│ ├── Bug76Test.php
│ └── BugFileByteStreamConsecutiveReadCallsTest.php
├── fixtures/
│ └── MimeEntityFixture.php
├── smoke/
│ └── Swift/
│ └── Smoke/
│ ├── AttachmentSmokeTest.php
│ ├── BasicSmokeTest.php
│ ├── HtmlWithAttachmentSmokeTest.php
│ └── InternationalSmokeTest.php
├── smoke.conf.php.default
└── unit/
└── Swift/
├── ByteStream/
│ └── ArrayByteStreamTest.php
├── CharacterReader/
│ ├── GenericFixedWidthReaderTest.php
│ ├── UsAsciiReaderTest.php
│ └── Utf8ReaderTest.php
├── CharacterStream/
│ └── ArrayCharacterStreamTest.php
├── DependencyContainerTest.php
├── Encoder/
│ ├── Base64EncoderTest.php
│ ├── QpEncoderTest.php
│ └── Rfc2231EncoderTest.php
├── Events/
│ ├── CommandEventTest.php
│ ├── EventObjectTest.php
│ ├── ResponseEventTest.php
│ ├── SendEventTest.php
│ ├── SimpleEventDispatcherTest.php
│ ├── TransportChangeEventTest.php
│ └── TransportExceptionEventTest.php
├── KeyCache/
│ ├── ArrayKeyCacheTest.php
│ └── SimpleKeyCacheInputStreamTest.php
├── Mailer/
│ └── ArrayRecipientIteratorTest.php
├── MailerTest.php
├── MessageTest.php
├── Mime/
│ ├── AbstractMimeEntityTest.php
│ ├── AttachmentTest.php
│ ├── ContentEncoder/
│ │ ├── Base64ContentEncoderTest.php
│ │ ├── PlainContentEncoderTest.php
│ │ └── QpContentEncoderTest.php
│ ├── EmbeddedFileTest.php
│ ├── HeaderEncoder/
│ │ ├── Base64HeaderEncoderTest.php
│ │ └── QpHeaderEncoderTest.php
│ ├── Headers/
│ │ ├── DateHeaderTest.php
│ │ ├── IdentificationHeaderTest.php
│ │ ├── MailboxHeaderTest.php
│ │ ├── ParameterizedHeaderTest.php
│ │ ├── PathHeaderTest.php
│ │ └── UnstructuredHeaderTest.php
│ ├── IdGeneratorTest.php
│ ├── MimePartTest.php
│ ├── SimpleHeaderFactoryTest.php
│ ├── SimpleHeaderSetTest.php
│ ├── SimpleMessageTest.php
│ └── SimpleMimeEntityTest.php
├── Plugins/
│ ├── AntiFloodPluginTest.php
│ ├── BandwidthMonitorPluginTest.php
│ ├── DecoratorPluginTest.php
│ ├── LoggerPluginTest.php
│ ├── Loggers/
│ │ ├── ArrayLoggerTest.php
│ │ └── EchoLoggerTest.php
│ ├── PopBeforeSmtpPluginTest.php
│ ├── RedirectingPluginTest.php
│ ├── ReporterPluginTest.php
│ ├── Reporters/
│ │ ├── HitReporterTest.php
│ │ └── HtmlReporterTest.php
│ └── ThrottlerPluginTest.php
├── Signers/
│ ├── DKIMSignerTest.php
│ ├── OpenDKIMSignerTest.php
│ └── SMimeSignerTest.php
├── StreamFilters/
│ ├── ByteArrayReplacementFilterTest.php
│ ├── StringReplacementFilterFactoryTest.php
│ └── StringReplacementFilterTest.php
└── Transport/
├── AbstractSmtpEventSupportTest.php
├── AbstractSmtpTest.php
├── Esmtp/
│ ├── Auth/
│ │ ├── CramMd5AuthenticatorTest.php
│ │ ├── LoginAuthenticatorTest.php
│ │ ├── NTLMAuthenticatorTest.php
│ │ └── PlainAuthenticatorTest.php
│ └── AuthHandlerTest.php
├── EsmtpTransport/
│ └── ExtensionSupportTest.php
├── EsmtpTransportTest.php
├── FailoverTransportTest.php
├── LoadBalancedTransportTest.php
├── SendmailTransportTest.php
└── StreamBufferTest.php
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitattributes
================================================
*.crt -crlf
*.key -crlf
*.srl -crlf
*.pub -crlf
*.priv -crlf
*.txt -crlf
# ignore directories in the git-generated distributed .zip archive
/doc/notes export-ignore
/tests export-ignore
/phpunit.xml.dist export-ignore
================================================
FILE: .github/ISSUE_TEMPLATE.md
================================================
| Q | A
| ------------------- | -----
| Bug report? | yes/no
| Feature request? | yes/no
| RFC? | yes/no
| How used? | Standalone/Symfony/3party
| Swiftmailer version | x.y.z
| PHP version | x.y.z
### Observed behaviour
### Expected behaviour
### Example
================================================
FILE: .github/PULL_REQUEST_TEMPLATE.md
================================================
| Q | A
| ------------- | ---
| Bug fix? | yes/no
| New feature? | yes/no
| Doc update? | yes/no
| BC breaks? | yes/no
| Deprecations? | yes/no
| Fixed tickets | #...
| License | MIT
================================================
FILE: .github/workflows/tests.yml
================================================
name: tests
on:
push:
pull_request:
jobs:
linux_tests:
runs-on: ubuntu-20.04
services:
mailcatcher:
image: dockage/mailcatcher:0.7.1
ports:
- 4456:1025
strategy:
fail-fast: true
matrix:
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
name: PHP ${{ matrix.php }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, intl
tools: composer:v2
coverage: none
- name: Prepare test config files
run: |
cp tests/acceptance.conf.php.default tests/acceptance.conf.php
cp tests/smoke.conf.php.default tests/smoke.conf.php
- name: Require Symfony PHPUnit Bridge 5.4 for PHP 8.1
if: ${{ matrix.php >= 8.1 }}
run: composer require symfony/phpunit-bridge:^5.4 --dev --prefer-dist --no-interaction --no-progress
- name: Install dependencies
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
- name: Execute tests
run: vendor/bin/simple-phpunit --verbose
env:
SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT: 1
================================================
FILE: .gitignore
================================================
/.php_cs.cache
/.phpunit
/.phpunit.result.cache
/build/*
/composer.lock
/phpunit.xml
/tests/acceptance.conf.php
/tests/smoke.conf.php
/vendor/
================================================
FILE: .php_cs.dist
================================================
setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit75Migration:risky' => true,
'php_unit_dedicate_assert' => ['target' => '5.6'],
'array_syntax' => ['syntax' => 'short'],
'php_unit_fqcn_annotation' => true,
'no_unreachable_default_argument_value' => false,
'braces' => ['allow_single_line_closure' => true],
'heredoc_to_nowdoc' => false,
'ordered_imports' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'all'],
'fopen_flags' => false,
])
->setRiskyAllowed(true)
->setFinder(PhpCsFixer\Finder::create()->in(__DIR__))
;
================================================
FILE: CHANGES
================================================
Changelog
=========
**Swiftmailer will stop being maintained at the end of November 2021.**
Please, move to Symfony Mailer at your earliest convenience.
Symfony Mailer is the next evolution of Swiftmailer.
It provides the same features with support for modern PHP code and support for third-party providers.
See https://symfony.com/doc/current/mailer.html for more information.
6.3.0 (2021-10-18)
------------------
* Fix support for PHP 8.1
6.2.7 (2021-03-09)
------------------
* Allow egulias/email-validator 3.1+
6.2.6 (2021-03-05)
------------------
* Fix Bcc support
6.2.5 (2021-01-12)
------------------
* Don't trust properties at destruct time
* Remove invalid PHPDocs param in EventDispatcher interface
* Bump license year
* Removes PHP version from README
6.2.4 (2020-12-08)
------------------
* Prevent flushing of the bubble queue when event handler raises another event
* Add support for PHP 8
* Code cleanups
6.2.3 (2019-11-12)
------------------
* no changes
6.2.2 (2019-11-12)
------------------
* fixed compat with PHP 7.4
* fixed error message when connecting to a stream raises an error before connect()
6.2.1 (2019-04-21)
------------------
* reverted "deprecated Swift_CharacterStream_ArrayCharacterStream and Swift_CharacterStream_NgCharacterStream in favor of Swift_CharacterStream_CharacterStream"
6.2.0 (2019-03-10)
------------------
* added support for symfony/polyfill-intl-dn
* deprecated Swift_CharacterStream_ArrayCharacterStream and Swift_CharacterStream_NgCharacterStream in favor of Swift_CharacterStream_CharacterStream
6.1.3 (2018-09-11)
------------------
* added auto-start to the SMTP transport when sending a message
* tweaked error message when the response from an SMTP server is empty
* fixed missing property in Swift_Mime_IdGenerator
* exposed original body content type with Swift_Mime_SimpleMimeEntity::getBodyContentType()
* fixed typo in variable name in Swift_AddressEncoder_IdnAddressEncoder
* fixed return type in MessageLogger
* fixed missing property addressEncoder in SimpleHeaderFactory class
6.1.2 (2018-07-13)
------------------
* handled recipient errors when pipelining
6.1.1 (2018-07-04)
------------------
* removed hard dependency on an IDN encoder
6.1.0 (2018-07-02)
------------------
* added address encoder exceptions during send
* added support for bubbling up authenticator error messages
* added support for non-ASCII email addresses
* introduced new dependencies: transport.smtphandlers and transport.authhandlers
* deprecated Swift_Signers_OpenDKIMSigner; use Swift_Signers_DKIMSigner instead
* added support for SMTP pipelining
* added Swift_Transport_Esmtp_EightBitMimeHandler
* fixed startTLS only allowed tls1.0, now allowed: tls1.0, tls1.1, tls1.2
6.0.2 (2017-09-30)
------------------
* fixed DecoratorPlugin
* removed usage of getmypid()
6.0.1 (2017-05-20)
------------------
* fixed BC break that can be avoided easily
6.0.0 (2017-05-19)
------------------
* added Swift_Transport::ping()
* removed Swift_Mime_HeaderFactory, Swift_Mime_HeaderSet, Swift_Mime_Message, Swift_Mime_MimeEntity,
and Swift_Mime_ParameterizedHeader interfaces
* removed Swift_MailTransport and Swift_Transport_MailTransport
* removed Swift_Encoding
* removed the Swift_Transport_MailInvoker interface and Swift_Transport_SimpleMailInvoker class
* removed the Swift_SignedMessage class
* removed newInstance() methods everywhere
* methods operating on Date header now use DateTimeImmutable object instead of Unix timestamp;
Swift_Mime_Headers_DateHeader::getTimestamp()/setTimestamp() renamed to getDateTime()/setDateTime()
* bumped minimum version to PHP 7.0
* removed Swift_Validate and replaced by egulias/email-validator
5.4.9 (2018-01-23)
------------------
* no changes, last version of the 5.x series
5.4.8 (2017-05-01)
------------------
* fixed encoding inheritance in addPart()
* fixed sorting MIME children when their types are equal
5.4.7 (2017-04-20)
------------------
* fixed NTLMAuthenticator clobbering bcmath scale
5.4.6 (2017-02-13)
------------------
* removed exceptions thrown in destructors as they lead to fatal errors
* switched to use sha256 by default in DKIM as per the RFC
* fixed an 'Undefined variable: pipes' PHP notice
* fixed long To headers when using the mail transport
* fixed NTLMAuthenticator when no domain is passed with the username
* prevented fatal error during unserialization of a message
* fixed a PHP warning when sending a message that has a length of a multiple of 8192
5.4.5 (2016-12-29)
------------------
* SECURITY FIX: fixed CVE-2016-10074 by disallowing potentially unsafe shell characters
Prior to 5.4.5, the mail transport (Swift_Transport_MailTransport) was vulnerable to passing
arbitrary shell arguments if the "From", "ReturnPath" or "Sender" header came
from a non-trusted source, potentially allowing Remote Code Execution
* deprecated the mail transport
5.4.4 (2016-11-23)
------------------
* reverted escaping command-line args to mail (PHP mail() function already does it)
5.4.3 (2016-07-08)
------------------
* fixed SimpleHeaderSet::has()/get() when the 0 index is removed
* removed the need to have mcrypt installed
* fixed broken MIME header encoding with quotes/colons and non-ascii chars
* allowed mail transport send for messages without To header
* fixed PHP 7 support
5.4.2 (2016-05-01)
------------------
* fixed support for IPv6 sockets
* added auto-retry when sending messages from the memory spool
* fixed consecutive read calls in Swift_ByteStream_FileByteStream
* added support for iso-8859-15 encoding
* fixed PHP mail extra params on missing reversePath
* added methods to set custom stream context options
* fixed charset changes in QpContentEncoderProxy
* added return-path header to the ignoredHeaders list of DKIMSigner
* fixed crlf for subject using mail
* fixed add soft line break only when necessary
* fixed escaping command-line args to mail
5.4.1 (2015-06-06)
------------------
* made Swiftmailer exceptions confirm to PHP base exception constructor signature
* fixed MAIL FROM & RCPT TO headers to be RFC compliant
5.4.0 (2015-03-14)
------------------
* added the possibility to add extra certs to PKCS#7 signature
* fix base64 encoding with streams
* added a new RESULT_SPOOLED status for SpoolTransport
* fixed getBody() on attachments when called more than once
* removed dots from generated filenames in filespool
5.3.1 (2014-12-05)
------------------
* fixed cloning of messages with attachments
5.3.0 (2014-10-04)
------------------
* fixed cloning when using signers
* reverted removal of Swift_Encoding
* drop support for PHP 5.2.x
5.2.2 (2014-09-20)
------------------
* fixed Japanese support
* fixed the memory spool when the message changes when in the pool
* added support for cloning messages
* fixed PHP warning in the redirect plugin
* changed the way to and cc-ed email are sent to only use one transaction
5.2.1 (2014-06-13)
------------------
* SECURITY FIX: fixed CLI escaping when using sendmail as a transport
Prior to 5.2.1, the sendmail transport (Swift_Transport_SendmailTransport)
was vulnerable to an arbitrary shell execution if the "From" header came
from a non-trusted source and no "Return-Path" is configured.
* fixed parameter in DKIMSigner
* fixed compatibility with PHP < 5.4
5.2.0 (2014-05-08)
------------------
* fixed Swift_ByteStream_FileByteStream::read() to match to the specification
* fixed from-charset and to-charset arguments in mbstring_convert_encoding() usages
* fixed infinite loop in StreamBuffer
* fixed NullTransport to return the number of ignored emails instead of 0
* Use phpunit and mockery for unit testing (realityking)
5.1.0 (2014-03-18)
------------------
* fixed data writing to stream when sending large messages
* added support for libopendkim (https://github.com/xdecock/php-opendkim)
* merged SignedMessage and Message
* added Gmail XOAuth2 authentication
* updated the list of known mime types
* added NTLM authentication
5.0.3 (2013-12-03)
------------------
* fixed double-dot bug
* fixed DKIM signer
5.0.2 (2013-08-30)
------------------
* handled correct exception type while reading IoBuffer output
5.0.1 (2013-06-17)
------------------
* changed the spool to only start the transport when a mail has to be sent
* fixed compatibility with PHP 5.2
* fixed LICENSE file
5.0.0 (2013-04-30)
------------------
* changed the license from LGPL to MIT
4.3.1 (2013-04-11)
------------------
* removed usage of the native QP encoder when the charset is not UTF-8
* fixed usage of uniqid to avoid collisions
* made a performance improvement when tokenizing large headers
* fixed usage of the PHP native QP encoder on PHP 5.4.7+
4.3.0 (2013-01-08)
------------------
* made the temporary directory configurable via the TMPDIR env variable
* added S/MIME signer and encryption support
4.2.2 (2012-10-25)
------------------
* added the possibility to throttle messages per second in ThrottlerPlugin (mostly for Amazon SES)
* switched mime.qpcontentencoder to automatically use the PHP native encoder on PHP 5.4.7+
* allowed specifying a whitelist with regular expressions in RedirectingPlugin
4.2.1 (2012-07-13)
------------------
* changed the coding standards to PSR-1/2
* fixed issue with autoloading
* added NativeQpContentEncoder to enhance performance (for PHP 5.3+)
4.2.0 (2012-06-29)
------------------
* added documentation about how to use the Japanese support introduced in 4.1.8
* added a way to override the default configuration in a lazy way
* changed the PEAR init script to lazy-load the initialization
* fixed a bug when calling Swift_Preferences before anything else (regression introduced in 4.1.8)
4.1.8 (2012-06-17)
------------------
* added Japanese iso-2022-jp support
* changed the init script to lazy-load the initialization
* fixed docblocks (@id) which caused some problems with libraries parsing the dobclocks
* fixed Swift_Mime_Headers_IdentificationHeader::setId() when passed an array of ids
* fixed encoding of email addresses in headers
* added replacements setter to the Decorator plugin
4.1.7 (2012-04-26)
------------------
* fixed QpEncoder safeMapShareId property
4.1.6 (2012-03-23)
------------------
* reduced the size of serialized Messages
4.1.5 (2012-01-04)
------------------
* enforced Swift_Spool::queueMessage() to return a Boolean
* made an optimization to the memory spool: start the transport only when required
* prevented stream_socket_client() from generating an error and throw a Swift_TransportException instead
* fixed a PHP warning when calling to mail() when safe_mode is off
* many doc tweaks
4.1.4 (2011-12-16)
------------------
* added a memory spool (Swift_MemorySpool)
* fixed too many opened files when sending emails with attachments
4.1.3 (2011-10-27)
------------------
* added STARTTLS support
* added missing @return tags on fluent methods
* added a MessageLogger plugin that logs all sent messages
* added composer.json
4.1.2 (2011-09-13)
------------------
* fixed wrong detection of magic_quotes_runtime
* fixed fatal errors when no To or Subject header has been set
* fixed charset on parameter header continuations
* added documentation about how to install Swiftmailer from the PEAR channel
* fixed various typos and markup problem in the documentation
* fixed warning when cache directory does not exist
* fixed "slashes are escaped" bug
* changed require_once() to require() in autoload
4.1.1 (2011-07-04)
------------------
* added missing file in PEAR package
4.1.0 (2011-06-30)
------------------
* documentation has been converted to ReST
4.1.0 RC1 (2011-06-17)
----------------------
New features:
* changed the Decorator Plugin to allow replacements in all headers
* added Swift_Mime_Grammar and Swift_Validate to validate an email address
* modified the autoloader to lazy-initialize Swiftmailer
* removed Swift_Mailer::batchSend()
* added NullTransport
* added new plugins: RedirectingPlugin and ImpersonatePlugin
* added a way to send messages asynchronously (Spool)
================================================
FILE: LICENSE
================================================
Copyright (c) 2013-2021 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
================================================
FILE: README.md
================================================
Swift Mailer
------------
**Swiftmailer will stop being maintained at the end of November 2021.**
Please, move to [Symfony Mailer](https://symfony.com/doc/current/mailer.html) at your earliest convenience.
[Symfony Mailer](https://symfony.com/doc/current/mailer.html) is the next evolution of Swiftmailer.
It provides the same features with support for modern PHP code and support for third-party providers.
Swift Mailer is a component based mailing solution for PHP.
It is released under the MIT license.
Swift Mailer is highly object-oriented by design and lends itself
to use in complex web application with a great deal of flexibility.
For full details on usage, read the [documentation](https://swiftmailer.symfony.com/docs/introduction.html).
Sponsors
--------
================================================
FILE: composer.json
================================================
{
"name": "swiftmailer/swiftmailer",
"type": "library",
"description": "Swiftmailer, free feature-rich PHP mailer",
"keywords": ["mail","mailer","email"],
"homepage": "https://swiftmailer.symfony.com",
"license": "MIT",
"authors": [
{
"name": "Chris Corbyn"
},
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}
],
"require": {
"php": ">=7.0.0",
"egulias/email-validator": "^2.0|^3.1",
"symfony/polyfill-iconv": "^1.0",
"symfony/polyfill-mbstring": "^1.0",
"symfony/polyfill-intl-idn": "^1.10"
},
"require-dev": {
"mockery/mockery": "^1.0",
"symfony/phpunit-bridge": "^4.4|^5.4"
},
"suggest": {
"ext-intl": "Needed to support internationalized email addresses"
},
"autoload": {
"files": ["lib/swift_required.php"]
},
"autoload-dev": {
"psr-0": { "Swift_": "tests/unit" }
},
"extra": {
"branch-alias": {
"dev-master": "6.2-dev"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
================================================
FILE: doc/headers.rst
================================================
Message Headers
===============
Sometimes you'll want to add your own headers to a message or modify/remove
headers that are already present. You work with the message's HeaderSet to do
this.
Header Basics
-------------
All MIME entities in Swift Mailer -- including the message itself -- store
their headers in a single object called a HeaderSet. This HeaderSet is
retrieved with the ``getHeaders()`` method.
As mentioned in the previous chapter, everything that forms a part of a message
in Swift Mailer is a MIME entity that is represented by an instance of
``Swift_Mime_SimpleMimeEntity``. This includes -- most notably -- the message
object itself, attachments, MIME parts and embedded images. Each of these MIME
entities consists of a body and a set of headers that describe the body.
For all of the "standard" headers in these MIME entities, such as the
``Content-Type``, there are named methods for working with them, such as
``setContentType()`` and ``getContentType()``. This is because headers are a
moderately complex area of the library. Each header has a slightly different
required structure that it must meet in order to comply with the standards that
govern email (and that are checked by spam blockers etc).
You fetch the HeaderSet from a MIME entity like so::
$message = new Swift_Message();
// Fetch the HeaderSet from a Message object
$headers = $message->getHeaders();
$attachment = Swift_Attachment::fromPath('document.pdf');
// Fetch the HeaderSet from an attachment object
$headers = $attachment->getHeaders();
The job of the HeaderSet is to contain and manage instances of Header objects.
Depending upon the MIME entity the HeaderSet came from, the contents of the
HeaderSet will be different, since an attachment for example has a different
set of headers to those in a message.
You can find out what the HeaderSet contains with a quick loop, dumping out the
names of the headers::
foreach ($headers->getAll() as $header) {
printf("%s \n", $header->getFieldName());
}
/*
Content-Transfer-Encoding
Content-Type
MIME-Version
Date
Message-ID
From
Subject
To
*/
You can also dump out the rendered HeaderSet by calling its ``toString()``
method::
echo $headers->toString();
/*
Message-ID: <1234869991.499a9ee7f1d5e@swift.generated>
Date: Tue, 17 Feb 2009 22:26:31 +1100
Subject: Awesome subject!
From: sender@example.org
To: recipient@example.org
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
*/
Where the complexity comes in is when you want to modify an existing header.
This complexity comes from the fact that each header can be of a slightly
different type (such as a Date header, or a header that contains email
addresses, or a header that has key-value parameters on it!). Each header in
the HeaderSet is an instance of ``Swift_Mime_Header``. They all have common
functionality, but knowing exactly what type of header you're working with will
allow you a little more control.
You can determine the type of header by comparing the return value of its
``getFieldType()`` method with the constants ``TYPE_TEXT``,
``TYPE_PARAMETERIZED``, ``TYPE_DATE``, ``TYPE_MAILBOX``, ``TYPE_ID`` and
``TYPE_PATH`` which are defined in ``Swift_Mime_Header``::
foreach ($headers->getAll() as $header) {
switch ($header->getFieldType()) {
case Swift_Mime_Header::TYPE_TEXT: $type = 'text';
break;
case Swift_Mime_Header::TYPE_PARAMETERIZED: $type = 'parameterized';
break;
case Swift_Mime_Header::TYPE_MAILBOX: $type = 'mailbox';
break;
case Swift_Mime_Header::TYPE_DATE: $type = 'date';
break;
case Swift_Mime_Header::TYPE_ID: $type = 'ID';
break;
case Swift_Mime_Header::TYPE_PATH: $type = 'path';
break;
}
printf("%s: is a %s header \n", $header->getFieldName(), $type);
}
/*
Content-Transfer-Encoding: is a text header
Content-Type: is a parameterized header
MIME-Version: is a text header
Date: is a date header
Message-ID: is a ID header
From: is a mailbox header
Subject: is a text header
To: is a mailbox header
*/
Headers can be removed from the set, modified within the set, or added to the
set.
The following sections show you how to work with the HeaderSet and explain the
details of each implementation of ``Swift_Mime_Header`` that may exist within
the HeaderSet.
Header Types
------------
Because all headers are modeled on different data (dates, addresses, text!)
there are different types of Header in Swift Mailer. Swift Mailer attempts to
categorize all possible MIME headers into more general groups, defined by a
small number of classes.
Text Headers
~~~~~~~~~~~~
Text headers are the simplest type of Header. They contain textual information
with no special information included within it -- for example the Subject
header in a message.
There's nothing particularly interesting about a text header, though it is
probably the one you'd opt to use if you need to add a custom header to a
message. It represents text just like you'd think it does. If the text contains
characters that are not permitted in a message header (such as new lines, or
non-ascii characters) then the header takes care of encoding the text so that
it can be used.
No header -- including text headers -- in Swift Mailer is vulnerable to
header-injection attacks. Swift Mailer breaks any attempt at header injection
by encoding the dangerous data into a non-dangerous form.
It's easy to add a new text header to a HeaderSet. You do this by calling the
HeaderSet's ``addTextHeader()`` method::
$message = new Swift_Message();
$headers = $message->getHeaders();
$headers->addTextHeader('Your-Header-Name', 'the header value');
Changing the value of an existing text header is done by calling it's
``setValue()`` method::
$subject = $message->getHeaders()->get('Subject');
$subject->setValue('new subject');
When output via ``toString()``, a text header produces something like the
following::
$subject = $message->getHeaders()->get('Subject');
$subject->setValue('amazing subject line');
echo $subject->toString();
/*
Subject: amazing subject line
*/
If the header contains any characters that are outside of the US-ASCII range
however, they will be encoded. This is nothing to be concerned about since mail
clients will decode them back::
$subject = $message->getHeaders()->get('Subject');
$subject->setValue('contains – dash');
echo $subject->toString();
/*
Subject: contains =?utf-8?Q?=E2=80=93?= dash
*/
Parameterized Headers
~~~~~~~~~~~~~~~~~~~~~
Parameterized headers are text headers that contain key-value parameters
following the textual content. The Content-Type header of a message is a
parameterized header since it contains charset information after the content
type.
The parameterized header type is a special type of text header. It extends the
text header by allowing additional information to follow it. All of the methods
from text headers are available in addition to the methods described here.
Adding a parameterized header to a HeaderSet is done by using the
``addParameterizedHeader()`` method which takes a text value like
``addTextHeader()`` but it also accepts an associative array of key-value
parameters::
$message = new Swift_Message();
$headers = $message->getHeaders();
$headers->addParameterizedHeader(
'Header-Name', 'header value',
['foo' => 'bar']
);
To change the text value of the header, call it's ``setValue()`` method just as
you do with text headers.
To change the parameters in the header, call the header's ``setParameters()``
method or the ``setParameter()`` method (note the pluralization)::
$type = $message->getHeaders()->get('Content-Type');
// setParameters() takes an associative array
$type->setParameters([
'name' => 'file.txt',
'charset' => 'iso-8859-1'
]);
// setParameter() takes two args for $key and $value
$type->setParameter('charset', 'iso-8859-1');
When output via ``toString()``, a parameterized header produces something like
the following::
$type = $message->getHeaders()->get('Content-Type');
$type->setValue('text/html');
$type->setParameter('charset', 'utf-8');
echo $type->toString();
/*
Content-Type: text/html; charset=utf-8
*/
If the header contains any characters that are outside of the US-ASCII range
however, they will be encoded, just like they are for text headers. This is
nothing to be concerned about since mail clients will decode them back.
Likewise, if the parameters contain any non-ascii characters they will be
encoded so that they can be transmitted safely::
$attachment = new Swift_Attachment();
$disp = $attachment->getHeaders()->get('Content-Disposition');
$disp->setValue('attachment');
$disp->setParameter('filename', 'report–may.pdf');
echo $disp->toString();
/*
Content-Disposition: attachment; filename*=utf-8''report%E2%80%93may.pdf
*/
Date Headers
~~~~~~~~~~~~
Date headers contains an RFC 2822 formatted date (i.e. what PHP's ``date('r')``
returns). They are used anywhere a date or time is needed to be presented as a
message header.
The data on which a date header is modeled as a DateTimeImmutable object. The
object is used to create a correctly structured RFC 2822 formatted date with
timezone such as ``Tue, 17 Feb 2009 22:26:31 +1100``.
The obvious place this header type is used is in the ``Date:`` header of the
message itself.
It's easy to add a new date header to a HeaderSet. You do this by calling the
HeaderSet's ``addDateHeader()`` method::
$message = new Swift_Message();
$headers = $message->getHeaders();
$headers->addDateHeader('Your-Header', new DateTimeImmutable('3 days ago'));
Changing the value of an existing date header is done by calling it's
``setDateTime()`` method::
$date = $message->getHeaders()->get('Date');
$date->setDateTime(new DateTimeImmutable());
When output via ``toString()``, a date header produces something like the
following::
$date = $message->getHeaders()->get('Date');
echo $date->toString();
/*
Date: Wed, 18 Feb 2009 13:35:02 +1100
*/
Mailbox (e-mail address) Headers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mailbox headers contain one or more email addresses, possibly with personalized
names attached to them. The data on which they are modeled is represented by an
associative array of email addresses and names.
Mailbox headers are probably the most complex header type to understand in
Swift Mailer because they accept their input as an array which can take various
forms, as described in the previous chapter.
All of the headers that contain e-mail addresses in a message -- with the
exception of ``Return-Path:`` which has a stricter syntax -- use this header
type. That is, ``To:``, ``From:`` etc.
You add a new mailbox header to a HeaderSet by calling the HeaderSet's
``addMailboxHeader()`` method::
$message = new Swift_Message();
$headers = $message->getHeaders();
$headers->addMailboxHeader('Your-Header-Name', [
'person1@example.org' => 'Person Name One',
'person2@example.org',
'person3@example.org',
'person4@example.org' => 'Another named person'
]);
Changing the value of an existing mailbox header is done by calling it's
``setNameAddresses()`` method::
$to = $message->getHeaders()->get('To');
$to->setNameAddresses([
'joe@example.org' => 'Joe Bloggs',
'john@example.org' => 'John Doe',
'no-name@example.org'
]);
If you don't wish to concern yourself with the complicated accepted input
formats accepted by ``setNameAddresses()`` as described in the previous chapter
and you only want to set one or more addresses (not names) then you can just
use the ``setAddresses()`` method instead::
$to = $message->getHeaders()->get('To');
$to->setAddresses([
'joe@example.org',
'john@example.org',
'no-name@example.org'
]);
.. note::
Both methods will accept the above input format in practice.
If all you want to do is set a single address in the header, you can use a
string as the input parameter to ``setAddresses()`` and/or
``setNameAddresses()``::
$to = $message->getHeaders()->get('To');
$to->setAddresses('joe-bloggs@example.org');
When output via ``toString()``, a mailbox header produces something like the
following::
$to = $message->getHeaders()->get('To');
$to->setNameAddresses([
'person1@example.org' => 'Name of Person',
'person2@example.org',
'person3@example.org' => 'Another Person'
]);
echo $to->toString();
/*
To: Name of Person , person2@example.org, Another Person
*/
Internationalized domains are automatically converted to IDN encoding::
$to = $message->getHeaders()->get('To');
$to->setAddresses('joe@ëxämple.org');
echo $to->toString();
/*
To: joe@xn--xmple-gra1c.org
*/
ID Headers
~~~~~~~~~~
ID headers contain identifiers for the entity (or the message). The most
notable ID header is the Message-ID header on the message itself.
An ID that exists inside an ID header looks more-or-less less like an email
address. For example, ``<1234955437.499becad62ec2@example.org>``. The part to
the left of the @ sign is usually unique, based on the current time and some
random factor. The part on the right is usually a domain name.
Any ID passed to the header's ``setId()`` method absolutely MUST conform to
this structure, otherwise you'll get an Exception thrown at you by Swift Mailer
(a ``Swift_RfcComplianceException``). This is to ensure that the generated
email complies with relevant RFC documents and therefore is less likely to be
blocked as spam.
It's easy to add a new ID header to a HeaderSet. You do this by calling the
HeaderSet's ``addIdHeader()`` method::
$message = new Swift_Message();
$headers = $message->getHeaders();
$headers->addIdHeader('Your-Header-Name', '123456.unqiue@example.org');
Changing the value of an existing ID header is done by calling its ``setId()``
method::
$msgId = $message->getHeaders()->get('Message-ID');
$msgId->setId(time() . '.' . uniqid('thing') . '@example.org');
When output via ``toString()``, an ID header produces something like the
following::
$msgId = $message->getHeaders()->get('Message-ID');
echo $msgId->toString();
/*
Message-ID: <1234955437.499becad62ec2@example.org>
*/
Path Headers
~~~~~~~~~~~~
Path headers are like very-restricted mailbox headers. They contain a single
email address with no associated name. The Return-Path header of a message is a
path header.
You add a new path header to a HeaderSet by calling the HeaderSet's
``addPathHeader()`` method::
$message = new Swift_Message();
$headers = $message->getHeaders();
$headers->addPathHeader('Your-Header-Name', 'person@example.org');
Changing the value of an existing path header is done by calling its
``setAddress()`` method::
$return = $message->getHeaders()->get('Return-Path');
$return->setAddress('my-address@example.org');
When output via ``toString()``, a path header produces something like the
following::
$return = $message->getHeaders()->get('Return-Path');
$return->setAddress('person@example.org');
echo $return->toString();
/*
Return-Path:
*/
Header Operations
-----------------
Working with the headers in a message involves knowing how to use the methods
on the HeaderSet and on the individual Headers within the HeaderSet.
Adding new Headers
~~~~~~~~~~~~~~~~~~
New headers can be added to the HeaderSet by using one of the provided
``add..Header()`` methods.
The added header will appear in the message when it is sent::
// Adding a custom header to a message
$message = new Swift_Message();
$headers = $message->getHeaders();
$headers->addTextHeader('X-Mine', 'something here');
// Adding a custom header to an attachment
$attachment = Swift_Attachment::fromPath('/path/to/doc.pdf');
$attachment->getHeaders()->addDateHeader('X-Created-Time', time());
Retrieving Headers
~~~~~~~~~~~~~~~~~~
Headers are retrieved through the HeaderSet's ``get()`` and ``getAll()``
methods::
$headers = $message->getHeaders();
// Get the To: header
$toHeader = $headers->get('To');
// Get all headers named "X-Foo"
$fooHeaders = $headers->getAll('X-Foo');
// Get the second header named "X-Foo"
$foo = $headers->get('X-Foo', 1);
// Get all headers that are present
$all = $headers->getAll();
When using ``get()`` a single header is returned that matches the name (case
insensitive) that is passed to it. When using ``getAll()`` with a header name,
an array of headers with that name are returned. Calling ``getAll()`` with no
arguments returns an array of all headers present in the entity.
.. note::
It's valid for some headers to appear more than once in a message (e.g.
the Received header). For this reason ``getAll()`` exists to fetch all
headers with a specified name. In addition, ``get()`` accepts an optional
numerical index, starting from zero to specify which header you want more
specifically.
.. note::
If you want to modify the contents of the header and you don't know for
sure what type of header it is then you may need to check the type by
calling its ``getFieldType()`` method.
Check if a Header Exists
~~~~~~~~~~~~~~~~~~~~~~~~
You can check if a named header is present in a HeaderSet by calling its
``has()`` method::
$headers = $message->getHeaders();
// Check if the To: header exists
if ($headers->has('To')) {
echo 'To: exists';
}
// Check if an X-Foo header exists twice (i.e. check for the 2nd one)
if ($headers->has('X-Foo', 1)) {
echo 'Second X-Foo header exists';
}
If the header exists, ``true`` will be returned or ``false`` if not.
.. note::
It's valid for some headers to appear more than once in a message (e.g.
the Received header). For this reason ``has()`` accepts an optional
numerical index, starting from zero to specify which header you want to
check more specifically.
Removing Headers
~~~~~~~~~~~~~~~~
Removing a Header from the HeaderSet is done by calling the HeaderSet's
``remove()`` or ``removeAll()`` methods::
$headers = $message->getHeaders();
// Remove the Subject: header
$headers->remove('Subject');
// Remove all X-Foo headers
$headers->removeAll('X-Foo');
// Remove only the second X-Foo header
$headers->remove('X-Foo', 1);
When calling ``remove()`` a single header will be removed. When calling
``removeAll()`` all headers with the given name will be removed. If no headers
exist with the given name, no errors will occur.
.. note::
It's valid for some headers to appear more than once in a message (e.g.
the Received header). For this reason ``remove()`` accepts an optional
numerical index, starting from zero to specify which header you want to
check more specifically. For the same reason, ``removeAll()`` exists to
remove all headers that have the given name.
Modifying a Header's Content
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To change a Header's content you should know what type of header it is and then
call it's appropriate setter method. All headers also have a
``setFieldBodyModel()`` method that accepts a mixed parameter and delegates to
the correct setter::
The header will be updated inside the HeaderSet and the changes will be seen
when the message is sent::
$headers = $message->getHeaders();
// Change the Subject: header
$subj = $headers->get('Subject');
$subj->setValue('new subject here');
// Change the To: header
$to = $headers->get('To');
$to->setNameAddresses([
'person@example.org' => 'Person',
'thing@example.org'
]);
// Using the setFieldBodyModel() just delegates to the correct method
// So here to calls setNameAddresses()
$to->setFieldBodyModel([
'person@example.org' => 'Person',
'thing@example.org'
]);
================================================
FILE: doc/index.rst
================================================
Swiftmailer
===========
.. toctree::
:maxdepth: 2
introduction
messages
headers
sending
plugins
japanese
================================================
FILE: doc/introduction.rst
================================================
Swift Mailer: A feature-rich PHP Mailer
=======================================
Swift Mailer is a component based library for sending e-mails from PHP applications.
**Swift Mailer will stop being maintained at the end of November 2021.**
Please, move to `Symfony Mailer `_ at your earliest convenience.
`Symfony Mailer `_ is the next evolution of Swift Mailer.
It provides the same features with support for modern PHP code and support for third-party providers.
System Requirements
-------------------
Swift Mailer supports PHP 7.0 to PHP 8.1 included (``proc_*`` functions must be
available).
Swift Mailer does not work when used with function overloading as implemented
by ``mbstring`` when ``mbstring.func_overload`` is set to ``2``.
Installation
------------
The recommended way to install Swiftmailer is via Composer:
.. code-block:: bash
$ composer require "swiftmailer/swiftmailer:^6.0"
Basic Usage
-----------
Here is the simplest way to send emails with Swift Mailer::
require_once '/path/to/vendor/autoload.php';
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.example.org', 25))
->setUsername('your username')
->setPassword('your password')
;
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
// Create a message
$message = (new Swift_Message('Wonderful Subject'))
->setFrom(['john@doe.com' => 'John Doe'])
->setTo(['receiver@domain.org', 'other@domain.org' => 'A name'])
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
You can also use Sendmail as a transport::
// Sendmail
$transport = new Swift_SendmailTransport('/usr/sbin/sendmail -bs');
Getting Help
------------
For general support, use `Stack Overflow `_.
For bug reports and feature requests, create a new ticket in `GitHub
`_.
================================================
FILE: doc/japanese.rst
================================================
Using Swift Mailer for Japanese Emails
======================================
To send emails in Japanese, you need to tweak the default configuration.
Call the ``Swift::init()`` method with the following code as early as possible
in your code::
Swift::init(function () {
Swift_DependencyContainer::getInstance()
->register('mime.qpheaderencoder')
->asAliasOf('mime.base64headerencoder');
Swift_Preferences::getInstance()->setCharset('iso-2022-jp');
});
/* rest of code goes here */
That's all!
================================================
FILE: doc/messages.rst
================================================
Creating Messages
=================
Creating messages in Swift Mailer is done by making use of the various MIME
entities provided with the library. Complex messages can be quickly created
with very little effort.
Quick Reference
---------------
You can think of creating a Message as being similar to the steps you perform
when you click the Compose button in your mail client. You give it a subject,
specify some recipients, add any attachments and write your message::
// Create the message
$message = (new Swift_Message())
// Give the message a subject
->setSubject('Your subject')
// Set the From address with an associative array
->setFrom(['john@doe.com' => 'John Doe'])
// Set the To addresses with an associative array (setTo/setCc/setBcc)
->setTo(['receiver@domain.org', 'other@domain.org' => 'A name'])
// Give it a body
->setBody('Here is the message itself')
// And optionally an alternative body
->addPart('Here is the message itself', 'text/html')
// Optionally add any attachments
->attach(Swift_Attachment::fromPath('my-document.pdf'))
;
Message Basics
--------------
A message is a container for anything you want to send to somebody else. There
are several basic aspects of a message that you should know.
An e-mail message is made up of several relatively simple entities that are
combined in different ways to achieve different results. All of these entities
have the same fundamental outline but serve a different purpose. The Message
itself can be defined as a MIME entity, an Attachment is a MIME entity, all
MIME parts are MIME entities -- and so on!
The basic units of each MIME entity -- be it the Message itself, or an
Attachment -- are its Headers and its body:
.. code-block:: text
Header-Name: A header value
Other-Header: Another value
The body content itself
The Headers of a MIME entity, and its body must conform to some strict
standards defined by various RFC documents. Swift Mailer ensures that these
specifications are followed by using various types of object, including
Encoders and different Header types to generate the entity.
The Structure of a Message
~~~~~~~~~~~~~~~~~~~~~~~~~~
Of all of the MIME entities, a message -- ``Swift_Message`` is the largest and
most complex. It has many properties that can be updated and it can contain
other MIME entities -- attachments for example -- nested inside it.
A Message has a lot of different Headers which are there to present information
about the message to the recipients' mail client. Most of these headers will be
familiar to the majority of users, but we'll list the basic ones. Although it's
possible to work directly with the Headers of a Message (or other MIME entity),
the standard Headers have accessor methods provided to abstract away the
complex details for you. For example, although the Date on a message is written
with a strict format, you only need to pass a DateTimeInterface instance to
``setDate()``.
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| Header | Description | Accessors |
+===============================+====================================================================================================================================+=============================================+
| ``Message-ID`` | Identifies this message with a unique ID, usually containing the domain name and time generated | ``getId()`` / ``setId()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| ``Return-Path`` | Specifies where bounces should go (Swift Mailer reads this for other uses) | ``getReturnPath()`` / ``setReturnPath()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| ``From`` | Specifies the address of the person who the message is from. This can be multiple addresses if multiple people wrote the message. | ``getFrom()`` / ``setFrom()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| ``Sender`` | Specifies the address of the person who physically sent the message (higher precedence than ``From:``) | ``getSender()`` / ``setSender()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| ``To`` | Specifies the addresses of the intended recipients | ``getTo()`` / ``setTo()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| ``Cc`` | Specifies the addresses of recipients who will be copied in on the message | ``getCc()`` / ``setCc()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| ``Bcc`` | Specifies the addresses of recipients who the message will be blind-copied to. Other recipients will not be aware of these copies. | ``getBcc()`` / ``setBcc()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| ``Reply-To`` | Specifies the address where replies are sent to | ``getReplyTo()`` / ``setReplyTo()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| ``Subject`` | Specifies the subject line that is displayed in the recipients' mail client | ``getSubject()`` / ``setSubject()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| ``Date`` | Specifies the date at which the message was sent | ``getDate()`` / ``setDate()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| ``Content-Type`` | Specifies the format of the message (usually ``text/plain`` or ``text/html``) | ``getContentType()`` / ``setContentType()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| ``Content-Transfer-Encoding`` | Specifies the encoding scheme in the message | ``getEncoder()`` / ``setEncoder()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
Working with a Message Object
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Although there are a lot of available methods on a message object, you only
need to make use of a small subset of them. Usually you'll use
``setSubject()``, ``setTo()`` and ``setFrom()`` before setting the body of your
message with ``setBody()``::
$message = new Swift_Message();
$message->setSubject('My subject');
All MIME entities (including a message) have a ``toString()`` method that you
can call if you want to take a look at what is going to be sent. For example,
if you ``echo $message->toString();`` you would see something like this:
.. code-block:: text
Message-ID: <1230173678.4952f5eeb1432@swift.generated>
Date: Thu, 25 Dec 2008 13:54:38 +1100
Subject: Example subject
From: Chris Corbyn
To: Receiver Name
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Here is the message
We'll take a closer look at the methods you use to create your message in the
following sections.
Adding Content to Your Message
------------------------------
Rich content can be added to messages in Swift Mailer with relative ease by
calling methods such as ``setSubject()``, ``setBody()``, ``addPart()`` and
``attach()``.
Setting the Subject Line
~~~~~~~~~~~~~~~~~~~~~~~~
The subject line, displayed in the recipients' mail client can be set with the
``setSubject()`` method, or as a parameter to ``new Swift_Message()``::
// Pass it as a parameter when you create the message
$message = new Swift_Message('My amazing subject');
// Or set it after like this
$message->setSubject('My amazing subject');
Setting the Body Content
~~~~~~~~~~~~~~~~~~~~~~~~
The body of the message -- seen when the user opens the message -- is specified
by calling the ``setBody()`` method. If an alternative body is to be included,
``addPart()`` can be used.
The body of a message is the main part that is read by the user. Often people
want to send a message in HTML format (``text/html``), other times people want
to send in plain text (``text/plain``), or sometimes people want to send both
versions and allow the recipient to choose how they view the message.
As a rule of thumb, if you're going to send a HTML email, always include a
plain-text equivalent of the same content so that users who prefer to read
plain text can do so.
If the recipient's mail client offers preferences for displaying text vs. HTML
then the mail client will present that part to the user where available. In
other cases the mail client will display the "best" part it can - usually HTML
if you've included HTML::
// Pass it as a parameter when you create the message
$message = new Swift_Message('Subject here', 'My amazing body');
// Or set it after like this
$message->setBody('My amazing body', 'text/html');
// Add alternative parts with addPart()
$message->addPart('My amazing body in plain text', 'text/plain');
Attaching Files
---------------
Attachments are downloadable parts of a message and can be added by calling the
``attach()`` method on the message. You can add attachments that exist on disk,
or you can create attachments on-the-fly.
Although we refer to files sent over e-mails as "attachments" -- because
they're attached to the message -- lots of other parts of the message are
actually "attached" even if we don't refer to these parts as attachments.
File attachments are created by the ``Swift_Attachment`` class and then
attached to the message via the ``attach()`` method on it. For all of the
"every day" MIME types such as all image formats, word documents, PDFs and
spreadsheets you don't need to explicitly set the content-type of the
attachment, though it would do no harm to do so. For less common formats you
should set the content-type -- which we'll cover in a moment.
Attaching Existing Files
~~~~~~~~~~~~~~~~~~~~~~~~
Files that already exist, either on disk or at a URL can be attached to a
message with just one line of code, using ``Swift_Attachment::fromPath()``.
You can attach files that exist locally, or if your PHP installation has
``allow_url_fopen`` turned on you can attach files from other
websites.
The attachment will be presented to the recipient as a downloadable file with
the same filename as the one you attached::
// Create the attachment
// * Note that you can technically leave the content-type parameter out
$attachment = Swift_Attachment::fromPath('/path/to/image.jpg', 'image/jpeg');
// Attach it to the message
$message->attach($attachment);
// The two statements above could be written in one line instead
$message->attach(Swift_Attachment::fromPath('/path/to/image.jpg'));
// You can attach files from a URL if allow_url_fopen is on in php.ini
$message->attach(Swift_Attachment::fromPath('http://site.tld/logo.png'));
Setting the Filename
~~~~~~~~~~~~~~~~~~~~
Usually you don't need to explicitly set the filename of an attachment because
the name of the attached file will be used by default, but if you want to set
the filename you use the ``setFilename()`` method of the Attachment.
The attachment will be attached in the normal way, but meta-data sent inside
the email will rename the file to something else::
// Create the attachment and call its setFilename() method
$attachment = Swift_Attachment::fromPath('/path/to/image.jpg')
->setFilename('cool.jpg');
// Because there's a fluid interface, you can do this in one statement
$message->attach(
Swift_Attachment::fromPath('/path/to/image.jpg')->setFilename('cool.jpg')
);
Attaching Dynamic Content
~~~~~~~~~~~~~~~~~~~~~~~~~
Files that are generated at runtime, such as PDF documents or images created
via GD can be attached directly to a message without writing them out to disk.
Use ``Swift_Attachment`` directly.
The attachment will be presented to the recipient as a downloadable file
with the filename and content-type you specify::
// Create your file contents in the normal way, but don't write them to disk
$data = create_my_pdf_data();
// Create the attachment with your data
$attachment = new Swift_Attachment($data, 'my-file.pdf', 'application/pdf');
// Attach it to the message
$message->attach($attachment);
// You can alternatively use method chaining to build the attachment
$attachment = (new Swift_Attachment())
->setFilename('my-file.pdf')
->setContentType('application/pdf')
->setBody($data)
;
.. note::
If you would usually write the file to disk anyway you should just attach
it with ``Swift_Attachment::fromPath()`` since this will use less memory.
Changing the Disposition
~~~~~~~~~~~~~~~~~~~~~~~~
Attachments just appear as files that can be saved to the Desktop if desired.
You can make attachment appear inline where possible by using the
``setDisposition()`` method of an attachment.
The attachment will be displayed within the email viewing window if the mail
client knows how to display it::
// Create the attachment and call its setDisposition() method
$attachment = Swift_Attachment::fromPath('/path/to/image.jpg')
->setDisposition('inline');
// Because there's a fluid interface, you can do this in one statement
$message->attach(
Swift_Attachment::fromPath('/path/to/image.jpg')->setDisposition('inline')
);
.. note::
If you try to create an inline attachment for a non-displayable file type
such as a ZIP file, the mail client should just present the attachment as
normal.
Embedding Inline Media Files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Often, people want to include an image or other content inline with a HTML
message. It's easy to do this with HTML linking to remote resources, but this
approach is usually blocked by mail clients. Swift Mailer allows you to embed
your media directly into the message.
Mail clients usually block downloads from remote resources because this
technique was often abused as a mean of tracking who opened an email. If
you're sending a HTML email and you want to include an image in the message
another approach you can take is to embed the image directly.
Swift Mailer makes embedding files into messages extremely streamlined. You
embed a file by calling the ``embed()`` method of the message,
which returns a value you can use in a ``src`` or
``href`` attribute in your HTML.
Just like with attachments, it's possible to embed dynamically generated
content without having an existing file available.
The embedded files are sent in the email as a special type of attachment that
has a unique ID used to reference them within your HTML attributes. On mail
clients that do not support embedded files they may appear as attachments.
Although this is commonly done for images, in theory it will work for any
displayable (or playable) media type. Support for other media types (such as
video) is dependent on the mail client however.
Embedding Existing Files
........................
Files that already exist, either on disk or at a URL can be embedded in a
message with just one line of code, using ``Swift_EmbeddedFile::fromPath()``.
You can embed files that exist locally, or if your PHP installation has
``allow_url_fopen`` turned on you can embed files from other websites.
The file will be displayed with the message inline with the HTML wherever its ID
is used as a ``src`` attribute::
// Create the message
$message = new Swift_Message('My subject');
// Set the body
$message->setBody(
'' .
' ' .
' Here is an image ' .
' Rest of message' .
' ' .
'',
'text/html' // Mark the content-type as HTML
);
// You can embed files from a URL if allow_url_fopen is on in php.ini
$message->setBody(
'' .
' ' .
' Here is an image ' .
' Rest of message' .
' ' .
'',
'text/html'
);
.. note::
``Swift_Image`` and ``Swift_EmbeddedFile`` are just aliases of one another.
``Swift_Image`` exists for semantic purposes.
.. note::
You can embed files in two stages if you prefer. Just capture the return
value of ``embed()`` in a variable and use that as the ``src`` attribute::
// If placing the embed() code inline becomes cumbersome
// it's easy to do this in two steps
$cid = $message->embed(Swift_Image::fromPath('image.png'));
$message->setBody(
'' .
' ' .
' Here is an image ' .
' Rest of message' .
' ' .
'',
'text/html' // Mark the content-type as HTML
);
Embedding Dynamic Content
.........................
Images that are generated at runtime, such as images created via GD can be
embedded directly to a message without writing them out to disk. Use the
standard ``new Swift_Image()`` method.
The file will be displayed with the message inline with the HTML wherever its ID
is used as a ``src`` attribute::
// Create your file contents in the normal way, but don't write them to disk
$img_data = create_my_image_data();
// Create the message
$message = new Swift_Message('My subject');
// Set the body
$message->setBody(
'' .
' ' .
' Here is an image ' .
' Rest of message' .
' ' .
'',
'text/html' // Mark the content-type as HTML
);
.. note::
``Swift_Image`` and ``Swift_EmbeddedFile`` are just aliases of one another.
``Swift_Image`` exists for semantic purposes.
.. note::
You can embed files in two stages if you prefer. Just capture the return
value of ``embed()`` in a variable and use that as the ``src`` attribute::
// If placing the embed() code inline becomes cumbersome
// it's easy to do this in two steps
$cid = $message->embed(new Swift_Image($img_data, 'image.jpg', 'image/jpeg'));
$message->setBody(
'' .
' ' .
' Here is an image ' .
' Rest of message' .
' ' .
'',
'text/html' // Mark the content-type as HTML
);
Adding Recipients to Your Message
---------------------------------
Recipients are specified within the message itself via ``setTo()``, ``setCc()``
and ``setBcc()``. Swift Mailer reads these recipients from the message when it
gets sent so that it knows where to send the message to.
Message recipients are one of three types:
* ``To:`` recipients -- the primary recipients (required)
* ``Cc:`` recipients -- receive a copy of the message (optional)
* ``Bcc:`` recipients -- hidden from other recipients (optional)
Each type can contain one, or several addresses. It's possible to list only the
addresses of the recipients, or you can personalize the address by providing
the real name of the recipient.
Make sure to add only valid email addresses as recipients. If you try to add an
invalid email address with ``setTo()``, ``setCc()`` or ``setBcc()``, Swift
Mailer will throw a ``Swift_RfcComplianceException``.
If you add recipients automatically based on a data source that may contain
invalid email addresses, you can prevent possible exceptions by validating the
addresses using::
use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\RFCValidation;
$validator = new EmailValidator();
$validator->isValid("example@example.com", new RFCValidation()); //true
and only adding addresses that validate. Another way would be to wrap your ``setTo()``, ``setCc()`` and
``setBcc()`` calls in a try-catch block and handle the
``Swift_RfcComplianceException`` in the catch block.
.. sidebar:: Syntax for Addresses
If you only wish to refer to a single email address (for example your
``From:`` address) then you can just use a string::
$message->setFrom('some@address.tld');
If you want to include a name then you must use an associative array::
$message->setFrom(['some@address.tld' => 'The Name']);
If you want to include multiple addresses then you must use an array::
$message->setTo(['some@address.tld', 'other@address.tld']);
You can mix personalized (addresses with a name) and non-personalized
addresses in the same list by mixing the use of associative and
non-associative array syntax::
$message->setTo([
'recipient-with-name@example.org' => 'Recipient Name One',
'no-name@example.org', // Note that this is not a key-value pair
'named-recipient@example.org' => 'Recipient Name Two'
]);
Setting ``To:`` Recipients
~~~~~~~~~~~~~~~~~~~~~~~~~~
``To:`` recipients are required in a message and are set with the ``setTo()``
or ``addTo()`` methods of the message.
To set ``To:`` recipients, create the message object using either ``new
Swift_Message( ... )``, then call the ``setTo()`` method with a complete array
of addresses, or use the ``addTo()`` method to iteratively add recipients.
The ``setTo()`` method accepts input in various formats as described earlier in
this chapter. The ``addTo()`` method takes either one or two parameters. The
first being the email address and the second optional parameter being the name
of the recipient.
``To:`` recipients are visible in the message headers and will be seen by the
other recipients::
// Using setTo() to set all recipients in one go
$message->setTo([
'person1@example.org',
'person2@otherdomain.org' => 'Person 2 Name',
'person3@example.org',
'person4@example.org',
'person5@example.org' => 'Person 5 Name'
]);
.. note::
Multiple calls to ``setTo()`` will not add new recipients -- each
call overrides the previous calls. If you want to iteratively add
recipients, use the ``addTo()`` method::
// Using addTo() to add recipients iteratively
$message->addTo('person1@example.org');
$message->addTo('person2@example.org', 'Person 2 Name');
Setting ``Cc:`` Recipients
~~~~~~~~~~~~~~~~~~~~~~~~~~
``Cc:`` recipients are set with the ``setCc()`` or ``addCc()`` methods of the
message.
To set ``Cc:`` recipients, create the message object using either ``new
Swift_Message( ... )``, then call the ``setCc()`` method with a complete array
of addresses, or use the ``addCc()`` method to iteratively add recipients.
The ``setCc()`` method accepts input in various formats as described earlier in
this chapter. The ``addCc()`` method takes either one or two parameters. The
first being the email address and the second optional parameter being the name
of the recipient.
``Cc:`` recipients are visible in the message headers and will be seen by the
other recipients::
// Using setTo() to set all recipients in one go
$message->setTo([
'person1@example.org',
'person2@otherdomain.org' => 'Person 2 Name',
'person3@example.org',
'person4@example.org',
'person5@example.org' => 'Person 5 Name'
]);
.. note::
Multiple calls to ``setCc()`` will not add new recipients -- each call
overrides the previous calls. If you want to iteratively add Cc:
recipients, use the ``addCc()`` method::
// Using addCc() to add recipients iteratively
$message->addCc('person1@example.org');
$message->addCc('person2@example.org', 'Person 2 Name');
Setting ``Bcc:`` Recipients
~~~~~~~~~~~~~~~~~~~~~~~~~~~
``Bcc:`` recipients receive a copy of the message without anybody else knowing
it, and are set with the ``setBcc()`` or ``addBcc()`` methods of the message.
To set ``Bcc:`` recipients, create the message object using either ``new
Swift_Message( ... )``, then call the ``setBcc()`` method with a complete array
of addresses, or use the ``addBcc()`` method to iteratively add recipients.
The ``setBcc()`` method accepts input in various formats as described earlier
in this chapter. The ``addBcc()`` method takes either one or two parameters.
The first being the email address and the second optional parameter being the
name of the recipient.
Only the individual ``Bcc:`` recipient will see their address in the message
headers. Other recipients (including other ``Bcc:`` recipients) will not see
the address::
// Using setBcc() to set all recipients in one go
$message->setBcc([
'person1@example.org',
'person2@otherdomain.org' => 'Person 2 Name',
'person3@example.org',
'person4@example.org',
'person5@example.org' => 'Person 5 Name'
]);
.. note::
Multiple calls to ``setBcc()`` will not add new recipients -- each call
overrides the previous calls. If you want to iteratively add Bcc:
recipients, use the ``addBcc()`` method::
// Using addBcc() to add recipients iteratively
$message->addBcc('person1@example.org');
$message->addBcc('person2@example.org', 'Person 2 Name');
.. sidebar:: Internationalized Email Addresses
Traditionally only ASCII characters have been allowed in email addresses.
With the introduction of internationalized domain names (IDNs), non-ASCII
characters may appear in the domain name. By default, Swiftmailer encodes
such domain names in Punycode (e.g. xn--xample-ova.invalid). This is
compatible with all mail servers.
RFC 6531 introduced an SMTP extension, SMTPUTF8, that allows non-ASCII
characters in email addresses on both sides of the @ sign. To send to such
addresses, your outbound SMTP server must support the SMTPUTF8 extension.
You should use the ``Swift_AddressEncoder_Utf8AddressEncoder`` address
encoder and enable the ``Swift_Transport_Esmtp_SmtpUtf8Handler`` SMTP
extension handler::
$smtpUtf8 = new Swift_Transport_Esmtp_SmtpUtf8Handler();
$transport->setExtensionHandlers([$smtpUtf8]);
$utf8Encoder = new Swift_AddressEncoder_Utf8AddressEncoder();
$transport->setAddressEncoder($utf8Encoder);
Specifying Sender Details
-------------------------
An email must include information about who sent it. Usually this is managed by
the ``From:`` address, however there are other options.
The sender information is contained in three possible places:
* ``From:`` -- the address(es) of who wrote the message (required)
* ``Sender:`` -- the address of the single person who sent the message
(optional)
* ``Return-Path:`` -- the address where bounces should go to (optional)
You must always include a ``From:`` address by using ``setFrom()`` on the
message. Swift Mailer will use this as the default ``Return-Path:`` unless
otherwise specified.
The ``Sender:`` address exists because the person who actually sent the email
may not be the person who wrote the email. It has a higher precedence than the
``From:`` address and will be used as the ``Return-Path:`` unless otherwise
specified.
Setting the ``From:`` Address
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A ``From:`` address is required and is set with the ``setFrom()`` method of the
message. ``From:`` addresses specify who actually wrote the email, and usually
who sent it.
What most people probably don't realize is that you can have more than one
``From:`` address if more than one person wrote the email -- for example if an
email was put together by a committee.
The ``From:`` address(es) are visible in the message headers and will be seen
by the recipients.
.. note::
If you set multiple ``From:`` addresses then you absolutely must set a
``Sender:`` address to indicate who physically sent the message.
::
// Set a single From: address
$message->setFrom('your@address.tld');
// Set a From: address including a name
$message->setFrom(['your@address.tld' => 'Your Name']);
// Set multiple From: addresses if multiple people wrote the email
$message->setFrom([
'person1@example.org' => 'Sender One',
'person2@example.org' => 'Sender Two'
]);
Setting the ``Sender:`` Address
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A ``Sender:`` address specifies who sent the message and is set with the
``setSender()`` method of the message.
The ``Sender:`` address is visible in the message headers and will be seen by
the recipients.
This address will be used as the ``Return-Path:`` unless otherwise specified.
.. note::
If you set multiple ``From:`` addresses then you absolutely must set a
``Sender:`` address to indicate who physically sent the message.
You must not set more than one sender address on a message because it's not
possible for more than one person to send a single message::
$message->setSender('your@address.tld');
Setting the ``Return-Path:`` (Bounce) Address
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``Return-Path:`` address specifies where bounce notifications should be
sent and is set with the ``setReturnPath()`` method of the message.
You can only have one ``Return-Path:`` and it must not include a personal name.
Bounce notifications will be sent to this address::
$message->setReturnPath('bounces@address.tld');
Signed/Encrypted Message
------------------------
To increase the integrity/security of a message it is possible to sign and/or
encrypt an message using one or multiple signers.
S/MIME
~~~~~~
S/MIME can sign and/or encrypt a message using the OpenSSL extension.
When signing a message, the signer creates a signature of the entire content of
the message (including attachments).
The certificate and private key must be PEM encoded, and can be either created
using for example OpenSSL or obtained at an official Certificate Authority (CA).
**The recipient must have the CA certificate in the list of trusted issuers in
order to verify the signature.**
**Make sure the certificate supports emailProtection.**
When using OpenSSL this can done by the including the *-addtrust
emailProtection* parameter when creating the certificate::
$message = new Swift_Message();
$smimeSigner = new Swift_Signers_SMimeSigner();
$smimeSigner->setSignCertificate('/path/to/certificate.pem', '/path/to/private-key.pem');
$message->attachSigner($smimeSigner);
When the private key is secured using a passphrase use the following instead::
$message = new Swift_Message();
$smimeSigner = new Swift_Signers_SMimeSigner();
$smimeSigner->setSignCertificate('/path/to/certificate.pem', ['/path/to/private-key.pem', 'passphrase']);
$message->attachSigner($smimeSigner);
By default the signature is added as attachment, making the message still
readable for mailing agents not supporting signed messages.
Storing the message as binary is also possible but not recommended::
$smimeSigner->setSignCertificate('/path/to/certificate.pem', '/path/to/private-key.pem', PKCS7_BINARY);
When encrypting the message (also known as enveloping), the entire message
(including attachments) is encrypted using a certificate, and the recipient can
then decrypt the message using corresponding private key.
Encrypting ensures nobody can read the contents of the message without the
private key.
Normally the recipient provides a certificate for encrypting and keeping the
decryption key private.
Using both signing and encrypting is also possible::
$message = new Swift_Message();
$smimeSigner = new Swift_Signers_SMimeSigner();
$smimeSigner->setSignCertificate('/path/to/sign-certificate.pem', '/path/to/private-key.pem');
$smimeSigner->setEncryptCertificate('/path/to/encrypt-certificate.pem');
$message->attachSigner($smimeSigner);
The used encryption cipher can be set as the second parameter of
setEncryptCertificate()
See https://secure.php.net/manual/openssl.ciphers for a list of supported ciphers.
By default the message is first signed and then encrypted, this can be changed
by adding::
$smimeSigner->setSignThenEncrypt(false);
**Changing this is not recommended as most mail agents don't support this
none-standard way.**
Only when having trouble with sign then encrypt method, this should be changed.
Requesting a Read Receipt
-------------------------
It is possible to request a read-receipt to be sent to an address when the
email is opened. To request a read receipt set the address with
``setReadReceiptTo()``::
$message->setReadReceiptTo('your@address.tld');
When the email is opened, if the mail client supports it a notification will be
sent to this address.
.. note::
Read receipts won't work for the majority of recipients since many mail
clients auto-disable them. Those clients that will send a read receipt
will make the user aware that one has been requested.
Setting the Character Set
-------------------------
The character set of the message (and its MIME parts) is set with the
``setCharset()`` method. You can also change the global default of UTF-8 by
working with the ``Swift_Preferences`` class.
Swift Mailer will default to the UTF-8 character set unless otherwise
overridden. UTF-8 will work in most instances since it includes all of the
standard US keyboard characters in addition to most international characters.
It is absolutely vital however that you know what character set your message
(or it's MIME parts) are written in otherwise your message may be received
completely garbled.
There are two places in Swift Mailer where you can change the character set:
* In the ``Swift_Preferences`` class
* On each individual message and/or MIME part
To set the character set of your Message:
* Change the global UTF-8 setting by calling
``Swift_Preferences::setCharset()``; or
* Call the ``setCharset()`` method on the message or the MIME part::
// Approach 1: Change the global setting (suggested)
Swift_Preferences::getInstance()->setCharset('iso-8859-2');
// Approach 2: Call the setCharset() method of the message
$message = (new Swift_Message())
->setCharset('iso-8859-2');
// Approach 3: Specify the charset when setting the body
$message->setBody('My body', 'text/html', 'iso-8859-2');
// Approach 4: Specify the charset for each part added
$message->addPart('My part', 'text/plain', 'iso-8859-2');
Setting the Encoding
--------------------
The body of each MIME part needs to be encoded. Binary attachments are encoded
in base64 using the ``Swift_Mime_ContentEncoder_Base64ContentEncoder``. Text
parts are traditionally encoded in quoted-printable using
``Swift_Mime_ContentEncoder_QpContentEncoder`` or
``Swift_Mime_ContentEncoder_NativeQpContentEncoder``.
The encoder of the message or MIME part is set with the ``setEncoder()`` method.
Quoted-printable is the safe choice, because it converts 8-bit text as 7-bit.
Most modern SMTP servers support 8-bit text. This is advertised via the 8BITMIME
SMTP extension. If your outbound SMTP server supports this SMTP extension, and
it supports downgrading the message (e.g converting to quoted-printable on the
fly) when delivering to a downstream server that does not support the extension,
you may wish to use ``Swift_Mime_ContentEncoder_PlainContentEncoder`` in
``8bit`` mode instead. This has the advantage that the source data is slightly
more readable and compact, especially for non-Western languages.
$eightBitMime = new Swift_Transport_Esmtp_EightBitMimeHandler();
$transport->setExtensionHandlers([$eightBitMime]);
$plainEncoder = new Swift_Mime_ContentEncoder_PlainContentEncoder('8bit');
$message->setEncoder($plainEncoder);
Setting the Line Length
-----------------------
The length of lines in a message can be changed by using the
``setMaxLineLength()`` method on the message::
$message->setMaxLineLength(1000);
Swift Mailer defaults to using 78 characters per line in a message. This is
done for historical reasons and so that the message can be easily viewed in
plain-text terminals
Lines that are longer than the line length specified will be wrapped between
words.
.. note::
You should never set a maximum length longer than 1000 characters
according to RFC 2822. Doing so could have unspecified side-effects such
as truncating parts of your message when it is transported between SMTP
servers.
Setting the Message Priority
----------------------------
You can change the priority of the message with ``setPriority()``. Setting the
priority will not change the way your email is sent -- it is purely an
indicative setting for the recipient::
// Indicate "High" priority
$message->setPriority(2);
The priority of a message is an indication to the recipient what significance
it has. Swift Mailer allows you to set the priority by calling the
``setPriority`` method. This method takes an integer value between 1 and 5:
* ``Swift_Mime_SimpleMessage::PRIORITY_HIGHEST``: 1
* ``Swift_Mime_SimpleMessage::PRIORITY_HIGH``: 2
* ``Swift_Mime_SimpleMessage::PRIORITY_NORMAL``: 3
* ``Swift_Mime_SimpleMessage::PRIORITY_LOW``: 4
* ``Swift_Mime_SimpleMessage::PRIORITY_LOWEST``: 5
::
// Or use the constant to be more explicit
$message->setPriority(Swift_Mime_SimpleMessage::PRIORITY_HIGH);
================================================
FILE: doc/notes/CHARSETS
================================================
Following is a list of character sets along with their widths:
--------------------------------------------------------------
1 Octet 8bit:
-------------
Windows 125* (CP125*)
CP*
ANSI
ISO-8859-* (IEC-8859-*)
Macintosh (Mac OS Roman)
KOI8-U (potentially KOI*8-*)
KOI8-R
MIK
Cork (T1)
ISCII
VISCII
1 Octet 7bit:
-------------
US-ASCII
K0I7
2 octets 16 bit:
----------------
UCS-2
UTF-16* (UTF-16BE etc)
4-octets 32 bit:
----------------
UCS-4
UTF-32
Variable-width:
----------------------------
Big5 - http://en.wikipedia.org/wiki/Big5 (1-2 bytes: 00-7f=1, 81-fe=2)
HKSCS - http://en.wikipedia.org/wiki/HKSCS (a big5 variant, but some variants use 10646)
ISO-10646 (IEC-10646) - http://en.wikipedia.org/wiki/ISO_10646 (unicode)
UTF-8 (1-5 bytes)
ISO-2022 (IEC-2022) - http://en.wikipedia.org/wiki/ISO_2022
Shift-JIS - http://en.wikipedia.org/wiki/Shift-JIS
A good resource:
----------------
http://en.wikipedia.org/wiki/Character_encoding#Simple_character_sets
================================================
FILE: doc/notes/rfc/rfc0821.txt
================================================
RFC 821
SIMPLE MAIL TRANSFER PROTOCOL
Jonathan B. Postel
August 1982
Information Sciences Institute
University of Southern California
4676 Admiralty Way
Marina del Rey, California 90291
(213) 822-1511
RFC 821 August 1982
Simple Mail Transfer Protocol
TABLE OF CONTENTS
1. INTRODUCTION .................................................. 1
2. THE SMTP MODEL ................................................ 2
3. THE SMTP PROCEDURE ............................................ 4
3.1. Mail ..................................................... 4
3.2. Forwarding ............................................... 7
3.3. Verifying and Expanding .................................. 8
3.4. Sending and Mailing ..................................... 11
3.5. Opening and Closing ..................................... 13
3.6. Relaying ................................................ 14
3.7. Domains ................................................. 17
3.8. Changing Roles .......................................... 18
4. THE SMTP SPECIFICATIONS ...................................... 19
4.1. SMTP Commands ........................................... 19
4.1.1. Command Semantics ..................................... 19
4.1.2. Command Syntax ........................................ 27
4.2. SMTP Replies ............................................ 34
4.2.1. Reply Codes by Function Group ......................... 35
4.2.2. Reply Codes in Numeric Order .......................... 36
4.3. Sequencing of Commands and Replies ...................... 37
4.4. State Diagrams .......................................... 39
4.5. Details ................................................. 41
4.5.1. Minimum Implementation ................................ 41
4.5.2. Transparency .......................................... 41
4.5.3. Sizes ................................................. 42
APPENDIX A: TCP ................................................. 44
APPENDIX B: NCP ................................................. 45
APPENDIX C: NITS ................................................ 46
APPENDIX D: X.25 ................................................ 47
APPENDIX E: Theory of Reply Codes ............................... 48
APPENDIX F: Scenarios ........................................... 51
GLOSSARY ......................................................... 64
REFERENCES ....................................................... 67
Network Working Group J. Postel
Request for Comments: DRAFT ISI
Replaces: RFC 788, 780, 772 August 1982
SIMPLE MAIL TRANSFER PROTOCOL
1. INTRODUCTION
The objective of Simple Mail Transfer Protocol (SMTP) is to transfer
mail reliably and efficiently.
SMTP is independent of the particular transmission subsystem and
requires only a reliable ordered data stream channel. Appendices A,
B, C, and D describe the use of SMTP with various transport services.
A Glossary provides the definitions of terms as used in this
document.
An important feature of SMTP is its capability to relay mail across
transport service environments. A transport service provides an
interprocess communication environment (IPCE). An IPCE may cover one
network, several networks, or a subset of a network. It is important
to realize that transport systems (or IPCEs) are not one-to-one with
networks. A process can communicate directly with another process
through any mutually known IPCE. Mail is an application or use of
interprocess communication. Mail can be communicated between
processes in different IPCEs by relaying through a process connected
to two (or more) IPCEs. More specifically, mail can be relayed
between hosts on different transport systems by a host on both
transport systems.
Postel [Page 1]
August 1982 RFC 821
Simple Mail Transfer Protocol
2. THE SMTP MODEL
The SMTP design is based on the following model of communication: as
the result of a user mail request, the sender-SMTP establishes a
two-way transmission channel to a receiver-SMTP. The receiver-SMTP
may be either the ultimate destination or an intermediate. SMTP
commands are generated by the sender-SMTP and sent to the
receiver-SMTP. SMTP replies are sent from the receiver-SMTP to the
sender-SMTP in response to the commands.
Once the transmission channel is established, the SMTP-sender sends a
MAIL command indicating the sender of the mail. If the SMTP-receiver
can accept mail it responds with an OK reply. The SMTP-sender then
sends a RCPT command identifying a recipient of the mail. If the
SMTP-receiver can accept mail for that recipient it responds with an
OK reply; if not, it responds with a reply rejecting that recipient
(but not the whole mail transaction). The SMTP-sender and
SMTP-receiver may negotiate several recipients. When the recipients
have been negotiated the SMTP-sender sends the mail data, terminating
with a special sequence. If the SMTP-receiver successfully processes
the mail data it responds with an OK reply. The dialog is purposely
lock-step, one-at-a-time.
-------------------------------------------------------------
+----------+ +----------+
+------+ | | | |
| User |<-->| | SMTP | |
+------+ | Sender- |Commands/Replies| Receiver-|
+------+ | SMTP |<-------------->| SMTP | +------+
| File |<-->| | and Mail | |<-->| File |
|System| | | | | |System|
+------+ +----------+ +----------+ +------+
Sender-SMTP Receiver-SMTP
Model for SMTP Use
Figure 1
-------------------------------------------------------------
The SMTP provides mechanisms for the transmission of mail; directly
from the sending user's host to the receiving user's host when the
[Page 2] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
two host are connected to the same transport service, or via one or
more relay SMTP-servers when the source and destination hosts are not
connected to the same transport service.
To be able to provide the relay capability the SMTP-server must be
supplied with the name of the ultimate destination host as well as
the destination mailbox name.
The argument to the MAIL command is a reverse-path, which specifies
who the mail is from. The argument to the RCPT command is a
forward-path, which specifies who the mail is to. The forward-path
is a source route, while the reverse-path is a return route (which
may be used to return a message to the sender when an error occurs
with a relayed message).
When the same message is sent to multiple recipients the SMTP
encourages the transmission of only one copy of the data for all the
recipients at the same destination host.
The mail commands and replies have a rigid syntax. Replies also have
a numeric code. In the following, examples appear which use actual
commands and replies. The complete lists of commands and replies
appears in Section 4 on specifications.
Commands and replies are not case sensitive. That is, a command or
reply word may be upper case, lower case, or any mixture of upper and
lower case. Note that this is not true of mailbox user names. For
some hosts the user name is case sensitive, and SMTP implementations
must take case to preserve the case of user names as they appear in
mailbox arguments. Host names are not case sensitive.
Commands and replies are composed of characters from the ASCII
character set [1]. When the transport service provides an 8-bit byte
(octet) transmission channel, each 7-bit character is transmitted
right justified in an octet with the high order bit cleared to zero.
When specifying the general form of a command or reply, an argument
(or special symbol) will be denoted by a meta-linguistic variable (or
constant), for example, "" or "". Here the
angle brackets indicate these are meta-linguistic variables.
However, some arguments use the angle brackets literally. For
example, an actual reverse-path is enclosed in angle brackets, i.e.,
"" is an instance of (the
angle brackets are actually transmitted in the command or reply).
Postel [Page 3]
August 1982 RFC 821
Simple Mail Transfer Protocol
3. THE SMTP PROCEDURES
This section presents the procedures used in SMTP in several parts.
First comes the basic mail procedure defined as a mail transaction.
Following this are descriptions of forwarding mail, verifying mailbox
names and expanding mailing lists, sending to terminals instead of or
in combination with mailboxes, and the opening and closing exchanges.
At the end of this section are comments on relaying, a note on mail
domains, and a discussion of changing roles. Throughout this section
are examples of partial command and reply sequences, several complete
scenarios are presented in Appendix F.
3.1. MAIL
There are three steps to SMTP mail transactions. The transaction
is started with a MAIL command which gives the sender
identification. A series of one or more RCPT commands follows
giving the receiver information. Then a DATA command gives the
mail data. And finally, the end of mail data indicator confirms
the transaction.
The first step in the procedure is the MAIL command. The
contains the source mailbox.
MAIL FROM:
This command tells the SMTP-receiver that a new mail
transaction is starting and to reset all its state tables and
buffers, including any recipients or mail data. It gives the
reverse-path which can be used to report errors. If accepted,
the receiver-SMTP returns a 250 OK reply.
The can contain more than just a mailbox. The
is a reverse source routing list of hosts and
source mailbox. The first host in the should be
the host sending this command.
The second step in the procedure is the RCPT command.
RCPT TO:
This command gives a forward-path identifying one recipient.
If accepted, the receiver-SMTP returns a 250 OK reply, and
stores the forward-path. If the recipient is unknown the
receiver-SMTP returns a 550 Failure reply. This second step of
the procedure can be repeated any number of times.
[Page 4] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
The can contain more than just a mailbox. The
is a source routing list of hosts and the
destination mailbox. The first host in the
should be the host receiving this command.
The third step in the procedure is the DATA command.
DATA
If accepted, the receiver-SMTP returns a 354 Intermediate reply
and considers all succeeding lines to be the message text.
When the end of text is received and stored the SMTP-receiver
sends a 250 OK reply.
Since the mail data is sent on the transmission channel the end
of the mail data must be indicated so that the command and
reply dialog can be resumed. SMTP indicates the end of the
mail data by sending a line containing only a period. A
transparency procedure is used to prevent this from interfering
with the user's text (see Section 4.5.2).
Please note that the mail data includes the memo header
items such as Date, Subject, To, Cc, From [2].
The end of mail data indicator also confirms the mail
transaction and tells the receiver-SMTP to now process the
stored recipients and mail data. If accepted, the
receiver-SMTP returns a 250 OK reply. The DATA command should
fail only if the mail transaction was incomplete (for example,
no recipients), or if resources are not available.
The above procedure is an example of a mail transaction. These
commands must be used only in the order discussed above.
Example 1 (below) illustrates the use of these commands in a mail
transaction.
Postel [Page 5]
August 1982 RFC 821
Simple Mail Transfer Protocol
-------------------------------------------------------------
Example of the SMTP Procedure
This SMTP example shows mail sent by Smith at host Alpha.ARPA,
to Jones, Green, and Brown at host Beta.ARPA. Here we assume
that host Alpha contacts host Beta directly.
S: MAIL FROM:
R: 250 OK
S: RCPT TO:
R: 250 OK
S: RCPT TO:
R: 550 No such user here
S: RCPT TO:
R: 250 OK
S: DATA
R: 354 Start mail input; end with .
S: Blah blah blah...
S: ...etc. etc. etc.
S: .
R: 250 OK
The mail has now been accepted for Jones and Brown. Green did
not have a mailbox at host Beta.
Example 1
-------------------------------------------------------------
[Page 6] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
3.2. FORWARDING
There are some cases where the destination information in the
is incorrect, but the receiver-SMTP knows the
correct destination. In such cases, one of the following replies
should be used to allow the sender to contact the correct
destination.
251 User not local; will forward to
This reply indicates that the receiver-SMTP knows the user's
mailbox is on another host and indicates the correct
forward-path to use in the future. Note that either the
host or user or both may be different. The receiver takes
responsibility for delivering the message.
551 User not local; please try
This reply indicates that the receiver-SMTP knows the user's
mailbox is on another host and indicates the correct
forward-path to use. Note that either the host or user or
both may be different. The receiver refuses to accept mail
for this user, and the sender must either redirect the mail
according to the information provided or return an error
response to the originating user.
Example 2 illustrates the use of these responses.
-------------------------------------------------------------
Example of Forwarding
Either
S: RCPT TO:
R: 251 User not local; will forward to
Or
S: RCPT TO:
R: 551 User not local; please try
Example 2
-------------------------------------------------------------
Postel [Page 7]
August 1982 RFC 821
Simple Mail Transfer Protocol
3.3. VERIFYING AND EXPANDING
SMTP provides as additional features, commands to verify a user
name or expand a mailing list. This is done with the VRFY and
EXPN commands, which have character string arguments. For the
VRFY command, the string is a user name, and the response may
include the full name of the user and must include the mailbox of
the user. For the EXPN command, the string identifies a mailing
list, and the multiline response may include the full name of the
users and must give the mailboxes on the mailing list.
"User name" is a fuzzy term and used purposely. If a host
implements the VRFY or EXPN commands then at least local mailboxes
must be recognized as "user names". If a host chooses to
recognize other strings as "user names" that is allowed.
In some hosts the distinction between a mailing list and an alias
for a single mailbox is a bit fuzzy, since a common data structure
may hold both types of entries, and it is possible to have mailing
lists of one mailbox. If a request is made to verify a mailing
list a positive response can be given if on receipt of a message
so addressed it will be delivered to everyone on the list,
otherwise an error should be reported (e.g., "550 That is a
mailing list, not a user"). If a request is made to expand a user
name a positive response can be formed by returning a list
containing one name, or an error can be reported (e.g., "550 That
is a user name, not a mailing list").
In the case of a multiline reply (normal for EXPN) exactly one
mailbox is to be specified on each line of the reply. In the case
of an ambiguous request, for example, "VRFY Smith", where there
are two Smith's the response must be "553 User ambiguous".
The case of verifying a user name is straightforward as shown in
example 3.
[Page 8] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
-------------------------------------------------------------
Example of Verifying a User Name
Either
S: VRFY Smith
R: 250 Fred Smith
Or
S: VRFY Smith
R: 251 User not local; will forward to
Or
S: VRFY Jones
R: 550 String does not match anything.
Or
S: VRFY Jones
R: 551 User not local; please try
Or
S: VRFY Gourzenkyinplatz
R: 553 User ambiguous.
Example 3
-------------------------------------------------------------
Postel [Page 9]
August 1982 RFC 821
Simple Mail Transfer Protocol
The case of expanding a mailbox list requires a multiline reply as
shown in example 4.
-------------------------------------------------------------
Example of Expanding a Mailing List
Either
S: EXPN Example-People
R: 250-Jon Postel
R: 250-Fred Fonebone
R: 250-Sam Q. Smith
R: 250-Quincy Smith <@USC-ISIF.ARPA:Q-Smith@ISI-VAXA.ARPA>
R: 250-
R: 250
Or
S: EXPN Executive-Washroom-List
R: 550 Access Denied to You.
Example 4
-------------------------------------------------------------
The character string arguments of the VRFY and EXPN commands
cannot be further restricted due to the variety of implementations
of the user name and mailbox list concepts. On some systems it
may be appropriate for the argument of the EXPN command to be a
file name for a file containing a mailing list, but again there is
a variety of file naming conventions in the Internet.
The VRFY and EXPN commands are not included in the minimum
implementation (Section 4.5.1), and are not required to work
across relays when they are implemented.
[Page 10] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
3.4. SENDING AND MAILING
The main purpose of SMTP is to deliver messages to user's
mailboxes. A very similar service provided by some hosts is to
deliver messages to user's terminals (provided the user is active
on the host). The delivery to the user's mailbox is called
"mailing", the delivery to the user's terminal is called
"sending". Because in many hosts the implementation of sending is
nearly identical to the implementation of mailing these two
functions are combined in SMTP. However the sending commands are
not included in the required minimum implementation
(Section 4.5.1). Users should have the ability to control the
writing of messages on their terminals. Most hosts permit the
users to accept or refuse such messages.
The following three command are defined to support the sending
options. These are used in the mail transaction instead of the
MAIL command and inform the receiver-SMTP of the special semantics
of this transaction:
SEND FROM:
The SEND command requires that the mail data be delivered to
the user's terminal. If the user is not active (or not
accepting terminal messages) on the host a 450 reply may
returned to a RCPT command. The mail transaction is
successful if the message is delivered the terminal.
SOML FROM:
The Send Or MaiL command requires that the mail data be
delivered to the user's terminal if the user is active (and
accepting terminal messages) on the host. If the user is
not active (or not accepting terminal messages) then the
mail data is entered into the user's mailbox. The mail
transaction is successful if the message is delivered either
to the terminal or the mailbox.
SAML FROM:
The Send And MaiL command requires that the mail data be
delivered to the user's terminal if the user is active (and
accepting terminal messages) on the host. In any case the
mail data is entered into the user's mailbox. The mail
transaction is successful if the message is delivered the
mailbox.
Postel [Page 11]
August 1982 RFC 821
Simple Mail Transfer Protocol
The same reply codes that are used for the MAIL commands are used
for these commands.
[Page 12] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
3.5. OPENING AND CLOSING
At the time the transmission channel is opened there is an
exchange to ensure that the hosts are communicating with the hosts
they think they are.
The following two commands are used in transmission channel
opening and closing:
HELO
QUIT
In the HELO command the host sending the command identifies
itself; the command may be interpreted as saying "Hello, I am
".
-------------------------------------------------------------
Example of Connection Opening
R: 220 BBN-UNIX.ARPA Simple Mail Transfer Service Ready
S: HELO USC-ISIF.ARPA
R: 250 BBN-UNIX.ARPA
Example 5
-------------------------------------------------------------
-------------------------------------------------------------
Example of Connection Closing
S: QUIT
R: 221 BBN-UNIX.ARPA Service closing transmission channel
Example 6
-------------------------------------------------------------
Postel [Page 13]
August 1982 RFC 821
Simple Mail Transfer Protocol
3.6. RELAYING
The forward-path may be a source route of the form
"@ONE,@TWO:JOE@THREE", where ONE, TWO, and THREE are hosts. This
form is used to emphasize the distinction between an address and a
route. The mailbox is an absolute address, and the route is
information about how to get there. The two concepts should not
be confused.
Conceptually the elements of the forward-path are moved to the
reverse-path as the message is relayed from one server-SMTP to
another. The reverse-path is a reverse source route, (i.e., a
source route from the current location of the message to the
originator of the message). When a server-SMTP deletes its
identifier from the forward-path and inserts it into the
reverse-path, it must use the name it is known by in the
environment it is sending into, not the environment the mail came
from, in case the server-SMTP is known by different names in
different environments.
If when the message arrives at an SMTP the first element of the
forward-path is not the identifier of that SMTP the element is not
deleted from the forward-path and is used to determine the next
SMTP to send the message to. In any case, the SMTP adds its own
identifier to the reverse-path.
Using source routing the receiver-SMTP receives mail to be relayed
to another server-SMTP The receiver-SMTP may accept or reject the
task of relaying the mail in the same way it accepts or rejects
mail for a local user. The receiver-SMTP transforms the command
arguments by moving its own identifier from the forward-path to
the beginning of the reverse-path. The receiver-SMTP then becomes
a sender-SMTP, establishes a transmission channel to the next SMTP
in the forward-path, and sends it the mail.
The first host in the reverse-path should be the host sending the
SMTP commands, and the first host in the forward-path should be
the host receiving the SMTP commands.
Notice that the forward-path and reverse-path appear in the SMTP
commands and replies, but not necessarily in the message. That
is, there is no need for these paths and especially this syntax to
appear in the "To:" , "From:", "CC:", etc. fields of the message
header.
If a server-SMTP has accepted the task of relaying the mail and
[Page 14] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
later finds that the forward-path is incorrect or that the mail
cannot be delivered for whatever reason, then it must construct an
"undeliverable mail" notification message and send it to the
originator of the undeliverable mail (as indicated by the
reverse-path).
This notification message must be from the server-SMTP at this
host. Of course, server-SMTPs should not send notification
messages about problems with notification messages. One way to
prevent loops in error reporting is to specify a null reverse-path
in the MAIL command of a notification message. When such a
message is relayed it is permissible to leave the reverse-path
null. A MAIL command with a null reverse-path appears as follows:
MAIL FROM:<>
An undeliverable mail notification message is shown in example 7.
This notification is in response to a message originated by JOE at
HOSTW and sent via HOSTX to HOSTY with instructions to relay it on
to HOSTZ. What we see in the example is the transaction between
HOSTY and HOSTX, which is the first step in the return of the
notification message.
Postel [Page 15]
August 1982 RFC 821
Simple Mail Transfer Protocol
-------------------------------------------------------------
Example Undeliverable Mail Notification Message
S: MAIL FROM:<>
R: 250 ok
S: RCPT TO:<@HOSTX.ARPA:JOE@HOSTW.ARPA>
R: 250 ok
S: DATA
R: 354 send the mail data, end with .
S: Date: 23 Oct 81 11:22:33
S: From: SMTP@HOSTY.ARPA
S: To: JOE@HOSTW.ARPA
S: Subject: Mail System Problem
S:
S: Sorry JOE, your message to SAM@HOSTZ.ARPA lost.
S: HOSTZ.ARPA said this:
S: "550 No Such User"
S: .
R: 250 ok
Example 7
-------------------------------------------------------------
[Page 16] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
3.7. DOMAINS
Domains are a recently introduced concept in the ARPA Internet
mail system. The use of domains changes the address space from a
flat global space of simple character string host names to a
hierarchically structured rooted tree of global addresses. The
host name is replaced by a domain and host designator which is a
sequence of domain element strings separated by periods with the
understanding that the domain elements are ordered from the most
specific to the most general.
For example, "USC-ISIF.ARPA", "Fred.Cambridge.UK", and
"PC7.LCS.MIT.ARPA" might be host-and-domain identifiers.
Whenever domain names are used in SMTP only the official names are
used, the use of nicknames or aliases is not allowed.
Postel [Page 17]
August 1982 RFC 821
Simple Mail Transfer Protocol
3.8. CHANGING ROLES
The TURN command may be used to reverse the roles of the two
programs communicating over the transmission channel.
If program-A is currently the sender-SMTP and it sends the TURN
command and receives an ok reply (250) then program-A becomes the
receiver-SMTP.
If program-B is currently the receiver-SMTP and it receives the
TURN command and sends an ok reply (250) then program-B becomes
the sender-SMTP.
To refuse to change roles the receiver sends the 502 reply.
Please note that this command is optional. It would not normally
be used in situations where the transmission channel is TCP.
However, when the cost of establishing the transmission channel is
high, this command may be quite useful. For example, this command
may be useful in supporting be mail exchange using the public
switched telephone system as a transmission channel, especially if
some hosts poll other hosts for mail exchanges.
[Page 18] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
4. THE SMTP SPECIFICATIONS
4.1. SMTP COMMANDS
4.1.1. COMMAND SEMANTICS
The SMTP commands define the mail transfer or the mail system
function requested by the user. SMTP commands are character
strings terminated by . The command codes themselves are
alphabetic characters terminated by if parameters follow
and otherwise. The syntax of mailboxes must conform to
receiver site conventions. The SMTP commands are discussed
below. The SMTP replies are discussed in the Section 4.2.
A mail transaction involves several data objects which are
communicated as arguments to different commands. The
reverse-path is the argument of the MAIL command, the
forward-path is the argument of the RCPT command, and the mail
data is the argument of the DATA command. These arguments or
data objects must be transmitted and held pending the
confirmation communicated by the end of mail data indication
which finalizes the transaction. The model for this is that
distinct buffers are provided to hold the types of data
objects, that is, there is a reverse-path buffer, a
forward-path buffer, and a mail data buffer. Specific commands
cause information to be appended to a specific buffer, or cause
one or more buffers to be cleared.
HELLO (HELO)
This command is used to identify the sender-SMTP to the
receiver-SMTP. The argument field contains the host name of
the sender-SMTP.
The receiver-SMTP identifies itself to the sender-SMTP in
the connection greeting reply, and in the response to this
command.
This command and an OK reply to it confirm that both the
sender-SMTP and the receiver-SMTP are in the initial state,
that is, there is no transaction in progress and all state
tables and buffers are cleared.
Postel [Page 19]
August 1982 RFC 821
Simple Mail Transfer Protocol
MAIL (MAIL)
This command is used to initiate a mail transaction in which
the mail data is delivered to one or more mailboxes. The
argument field contains a reverse-path.
The reverse-path consists of an optional list of hosts and
the sender mailbox. When the list of hosts is present, it
is a "reverse" source route and indicates that the mail was
relayed through each host on the list (the first host in the
list was the most recent relay). This list is used as a
source route to return non-delivery notices to the sender.
As each relay host adds itself to the beginning of the list,
it must use its name as known in the IPCE to which it is
relaying the mail rather than the IPCE from which the mail
came (if they are different). In some types of error
reporting messages (for example, undeliverable mail
notifications) the reverse-path may be null (see Example 7).
This command clears the reverse-path buffer, the
forward-path buffer, and the mail data buffer; and inserts
the reverse-path information from this command into the
reverse-path buffer.
RECIPIENT (RCPT)
This command is used to identify an individual recipient of
the mail data; multiple recipients are specified by multiple
use of this command.
The forward-path consists of an optional list of hosts and a
required destination mailbox. When the list of hosts is
present, it is a source route and indicates that the mail
must be relayed to the next host on the list. If the
receiver-SMTP does not implement the relay function it may
user the same reply it would for an unknown local user
(550).
When mail is relayed, the relay host must remove itself from
the beginning forward-path and put itself at the beginning
of the reverse-path. When mail reaches its ultimate
destination (the forward-path contains only a destination
mailbox), the receiver-SMTP inserts it into the destination
mailbox in accordance with its host mail conventions.
[Page 20] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
For example, mail received at relay host A with arguments
FROM:
TO:<@HOSTA.ARPA,@HOSTB.ARPA:USERC@HOSTD.ARPA>
will be relayed on to host B with arguments
FROM:<@HOSTA.ARPA:USERX@HOSTY.ARPA>
TO:<@HOSTB.ARPA:USERC@HOSTD.ARPA>.
This command causes its forward-path argument to be appended
to the forward-path buffer.
DATA (DATA)
The receiver treats the lines following the command as mail
data from the sender. This command causes the mail data
from this command to be appended to the mail data buffer.
The mail data may contain any of the 128 ASCII character
codes.
The mail data is terminated by a line containing only a
period, that is the character sequence "." (see
Section 4.5.2 on Transparency). This is the end of mail
data indication.
The end of mail data indication requires that the receiver
must now process the stored mail transaction information.
This processing consumes the information in the reverse-path
buffer, the forward-path buffer, and the mail data buffer,
and on the completion of this command these buffers are
cleared. If the processing is successful the receiver must
send an OK reply. If the processing fails completely the
receiver must send a failure reply.
When the receiver-SMTP accepts a message either for relaying
or for final delivery it inserts at the beginning of the
mail data a time stamp line. The time stamp line indicates
the identity of the host that sent the message, and the
identity of the host that received the message (and is
inserting this time stamp), and the date and time the
message was received. Relayed messages will have multiple
time stamp lines.
When the receiver-SMTP makes the "final delivery" of a
message it inserts at the beginning of the mail data a
Postel [Page 21]
August 1982 RFC 821
Simple Mail Transfer Protocol
return path line. The return path line preserves the
information in the from the MAIL command.
Here, final delivery means the message leaves the SMTP
world. Normally, this would mean it has been delivered to
the destination user, but in some cases it may be further
processed and transmitted by another mail system.
It is possible for the mailbox in the return path be
different from the actual sender's mailbox, for example,
if error responses are to be delivered a special error
handling mailbox rather than the message senders.
The preceding two paragraphs imply that the final mail data
will begin with a return path line, followed by one or more
time stamp lines. These lines will be followed by the mail
data header and body [2]. See Example 8.
Special mention is needed of the response and further action
required when the processing following the end of mail data
indication is partially successful. This could arise if
after accepting several recipients and the mail data, the
receiver-SMTP finds that the mail data can be successfully
delivered to some of the recipients, but it cannot be to
others (for example, due to mailbox space allocation
problems). In such a situation, the response to the DATA
command must be an OK reply. But, the receiver-SMTP must
compose and send an "undeliverable mail" notification
message to the originator of the message. Either a single
notification which lists all of the recipients that failed
to get the message, or separate notification messages must
be sent for each failed recipient (see Example 7). All
undeliverable mail notification messages are sent using the
MAIL command (even if they result from processing a SEND,
SOML, or SAML command).
[Page 22] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
-------------------------------------------------------------
Example of Return Path and Received Time Stamps
Return-Path: <@GHI.ARPA,@DEF.ARPA,@ABC.ARPA:JOE@ABC.ARPA>
Received: from GHI.ARPA by JKL.ARPA ; 27 Oct 81 15:27:39 PST
Received: from DEF.ARPA by GHI.ARPA ; 27 Oct 81 15:15:13 PST
Received: from ABC.ARPA by DEF.ARPA ; 27 Oct 81 15:01:59 PST
Date: 27 Oct 81 15:01:01 PST
From: JOE@ABC.ARPA
Subject: Improved Mailing System Installed
To: SAM@JKL.ARPA
This is to inform you that ...
Example 8
-------------------------------------------------------------
SEND (SEND)
This command is used to initiate a mail transaction in which
the mail data is delivered to one or more terminals. The
argument field contains a reverse-path. This command is
successful if the message is delivered to a terminal.
The reverse-path consists of an optional list of hosts and
the sender mailbox. When the list of hosts is present, it
is a "reverse" source route and indicates that the mail was
relayed through each host on the list (the first host in the
list was the most recent relay). This list is used as a
source route to return non-delivery notices to the sender.
As each relay host adds itself to the beginning of the list,
it must use its name as known in the IPCE to which it is
relaying the mail rather than the IPCE from which the mail
came (if they are different).
This command clears the reverse-path buffer, the
forward-path buffer, and the mail data buffer; and inserts
the reverse-path information from this command into the
reverse-path buffer.
SEND OR MAIL (SOML)
This command is used to initiate a mail transaction in which
the mail data is delivered to one or more terminals or
Postel [Page 23]
August 1982 RFC 821
Simple Mail Transfer Protocol
mailboxes. For each recipient the mail data is delivered to
the recipient's terminal if the recipient is active on the
host (and accepting terminal messages), otherwise to the
recipient's mailbox. The argument field contains a
reverse-path. This command is successful if the message is
delivered to a terminal or the mailbox.
The reverse-path consists of an optional list of hosts and
the sender mailbox. When the list of hosts is present, it
is a "reverse" source route and indicates that the mail was
relayed through each host on the list (the first host in the
list was the most recent relay). This list is used as a
source route to return non-delivery notices to the sender.
As each relay host adds itself to the beginning of the list,
it must use its name as known in the IPCE to which it is
relaying the mail rather than the IPCE from which the mail
came (if they are different).
This command clears the reverse-path buffer, the
forward-path buffer, and the mail data buffer; and inserts
the reverse-path information from this command into the
reverse-path buffer.
SEND AND MAIL (SAML)
This command is used to initiate a mail transaction in which
the mail data is delivered to one or more terminals and
mailboxes. For each recipient the mail data is delivered to
the recipient's terminal if the recipient is active on the
host (and accepting terminal messages), and for all
recipients to the recipient's mailbox. The argument field
contains a reverse-path. This command is successful if the
message is delivered to the mailbox.
The reverse-path consists of an optional list of hosts and
the sender mailbox. When the list of hosts is present, it
is a "reverse" source route and indicates that the mail was
relayed through each host on the list (the first host in the
list was the most recent relay). This list is used as a
source route to return non-delivery notices to the sender.
As each relay host adds itself to the beginning of the list,
it must use its name as known in the IPCE to which it is
relaying the mail rather than the IPCE from which the mail
came (if they are different).
This command clears the reverse-path buffer, the
[Page 24] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
forward-path buffer, and the mail data buffer; and inserts
the reverse-path information from this command into the
reverse-path buffer.
RESET (RSET)
This command specifies that the current mail transaction is
to be aborted. Any stored sender, recipients, and mail data
must be discarded, and all buffers and state tables cleared.
The receiver must send an OK reply.
VERIFY (VRFY)
This command asks the receiver to confirm that the argument
identifies a user. If it is a user name, the full name of
the user (if known) and the fully specified mailbox are
returned.
This command has no effect on any of the reverse-path
buffer, the forward-path buffer, or the mail data buffer.
EXPAND (EXPN)
This command asks the receiver to confirm that the argument
identifies a mailing list, and if so, to return the
membership of that list. The full name of the users (if
known) and the fully specified mailboxes are returned in a
multiline reply.
This command has no effect on any of the reverse-path
buffer, the forward-path buffer, or the mail data buffer.
HELP (HELP)
This command causes the receiver to send helpful information
to the sender of the HELP command. The command may take an
argument (e.g., any command name) and return more specific
information as a response.
This command has no effect on any of the reverse-path
buffer, the forward-path buffer, or the mail data buffer.
Postel [Page 25]
August 1982 RFC 821
Simple Mail Transfer Protocol
NOOP (NOOP)
This command does not affect any parameters or previously
entered commands. It specifies no action other than that
the receiver send an OK reply.
This command has no effect on any of the reverse-path
buffer, the forward-path buffer, or the mail data buffer.
QUIT (QUIT)
This command specifies that the receiver must send an OK
reply, and then close the transmission channel.
The receiver should not close the transmission channel until
it receives and replies to a QUIT command (even if there was
an error). The sender should not close the transmission
channel until it send a QUIT command and receives the reply
(even if there was an error response to a previous command).
If the connection is closed prematurely the receiver should
act as if a RSET command had been received (canceling any
pending transaction, but not undoing any previously
completed transaction), the sender should act as if the
command or transaction in progress had received a temporary
error (4xx).
TURN (TURN)
This command specifies that the receiver must either (1)
send an OK reply and then take on the role of the
sender-SMTP, or (2) send a refusal reply and retain the role
of the receiver-SMTP.
If program-A is currently the sender-SMTP and it sends the
TURN command and receives an OK reply (250) then program-A
becomes the receiver-SMTP. Program-A is then in the initial
state as if the transmission channel just opened, and it
then sends the 220 service ready greeting.
If program-B is currently the receiver-SMTP and it receives
the TURN command and sends an OK reply (250) then program-B
becomes the sender-SMTP. Program-B is then in the initial
state as if the transmission channel just opened, and it
then expects to receive the 220 service ready greeting.
To refuse to change roles the receiver sends the 502 reply.
[Page 26] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
There are restrictions on the order in which these command may
be used.
The first command in a session must be the HELO command.
The HELO command may be used later in a session as well. If
the HELO command argument is not acceptable a 501 failure
reply must be returned and the receiver-SMTP must stay in
the same state.
The NOOP, HELP, EXPN, and VRFY commands can be used at any
time during a session.
The MAIL, SEND, SOML, or SAML commands begin a mail
transaction. Once started a mail transaction consists of
one of the transaction beginning commands, one or more RCPT
commands, and a DATA command, in that order. A mail
transaction may be aborted by the RSET command. There may
be zero or more transactions in a session.
If the transaction beginning command argument is not
acceptable a 501 failure reply must be returned and the
receiver-SMTP must stay in the same state. If the commands
in a transaction are out of order a 503 failure reply must
be returned and the receiver-SMTP must stay in the same
state.
The last command in a session must be the QUIT command. The
QUIT command can not be used at any other time in a session.
4.1.2. COMMAND SYNTAX
The commands consist of a command code followed by an argument
field. Command codes are four alphabetic characters. Upper
and lower case alphabetic characters are to be treated
identically. Thus, any of the following may represent the mail
command:
MAIL Mail mail MaIl mAIl
This also applies to any symbols representing parameter values,
such as "TO" or "to" for the forward-path. Command codes and
the argument fields are separated by one or more spaces.
However, within the reverse-path and forward-path arguments
case is important. In particular, in some hosts the user
"smith" is different from the user "Smith".
Postel [Page 27]
August 1982 RFC 821
Simple Mail Transfer Protocol
The argument field consists of a variable length character
string ending with the character sequence . The receiver
is to take no action until this sequence is received.
Square brackets denote an optional argument field. If the
option is not taken, the appropriate default is implied.
[Page 28] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
The following are the SMTP commands:
HELO
MAIL FROM:
RCPT TO:
DATA
RSET
SEND FROM:
SOML FROM:
SAML FROM:
VRFY
EXPN
HELP []
NOOP
QUIT
TURN
Postel [Page 29]
August 1982 RFC 821
Simple Mail Transfer Protocol
The syntax of the above argument fields (using BNF notation
where applicable) is given below. The "..." notation indicates
that a field may be repeated one or more times.
::= ::= ::= "<" [ ":" ] ">"
::= | "," ::= "@" ::= | "." ::= | "#" | "[" "]"
::= "@" ::= | ::= ::= | ::= | ::= | | "-"
::= | "." ::= | ::= """ """
::= "\" | "\" | | ::= | "\" ::= "." "." "." ::= | ::=
[Page 30] Postel
RFC 821 August 1982
Simple Mail Transfer Protocol
::= the carriage return character (ASCII code 13)
::= the line feed character (ASCII code 10)
::= the space character (ASCII code 32)
::= one, two, or three digits representing a decimal
integer value in the range 0 through 255
::= any one of the 52 alphabetic characters A through Z
in upper case and a through z in lower case
::= any one of the 128 ASCII characters, but not any
or ::= any one of the ten digits 0 through 9
::= any one of the 128 ASCII characters except ,
, quote ("), or backslash (\)
::= any one of the 128 ASCII characters (no exceptions)
::= "<" | ">" | "(" | ")" | "[" | "]" | "\" | "."
| "," | ";" | ":" | "@" """ | the control
characters (ASCII codes 0 through 31 inclusive and
127)
Note that the backslash, "\", is a quote character, which is
used to indicate that the next character is to be used
literally (instead of its normal interpretation). For example,
"Joe\,Smith" could be used to indicate a single nine character
user field with comma being the fourth character of the field.
Hosts are generally known by names which are translated to
addresses in each host. Note that the name elements of domains
are the official names -- no use of nicknames or aliases is
allowed.
Sometimes a host is not known to the translation function and
communication is blocked. To bypass this barrier two numeric
forms are also allowed for host "names". One form is a decimal
integer prefixed by a pound sign, "#", which indicates the
number is the address of the host. Another form is four small
decimal integers separated by dots and enclosed by brackets,
e.g., "[123.255.37.2]", which indicates a 32-bit ARPA Internet
Address in four 8-bit fields.
Postel [Page 31]
August 1982 RFC 821
Simple Mail Transfer Protocol
The time stamp line and the return path line are formally
defined as follows:
::= "Return-Path:" ::= "Received:" ::= ";"
::= "FROM" ::= "BY" ::= [] [] [] []
::= "VIA" ::= "WITH" ::= "ID" ::= "FOR"
::= The standard names for links are registered with
the Network Information Center.
::= The standard names for protocols are
registered with the Network Information Center.
::=