3 * @see https://github.com/zendframework/zend-mail for the canonical source repository
4 * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5 * @license https://github.com/zendframework/zend-mail/blob/master/LICENSE.md New BSD License
8 namespace Zend\Mail\Transport
;
10 use Zend\Mail\Exception
;
11 use Zend\Stdlib\AbstractOptions
;
13 class SmtpOptions
extends AbstractOptions
16 * @var string Local client hostname
18 protected $name = 'localhost';
23 protected $connectionClass = 'smtp';
26 * Connection configuration (passed to the underlying Protocol class)
30 protected $connectionConfig = [];
33 * @var string Remote SMTP hostname or IP
35 protected $host = '127.0.0.1';
43 * The timeout in seconds for the SMTP connection
44 * (Use null to disable it)
48 protected $connectionTimeLimit;
51 * Return the local client hostname
55 public function getName()
61 * Set the local client hostname or IP
63 * @todo hostname/IP validation
65 * @throws \Zend\Mail\Exception\InvalidArgumentException
68 public function setName($name)
70 if (! is_string($name) && $name !== null) {
71 throw new Exception\
InvalidArgumentException(sprintf(
72 'Name must be a string or null; argument of type "%s" provided',
73 (is_object($name) ?
get_class($name) : gettype($name))
81 * Get connection class
83 * This should be either the class Zend\Mail\Protocol\Smtp or a class
84 * extending it -- typically a class in the Zend\Mail\Protocol\Smtp\Auth
89 public function getConnectionClass()
91 return $this->connectionClass
;
95 * Set connection class
97 * @param string $connectionClass the value to be set
98 * @throws \Zend\Mail\Exception\InvalidArgumentException
101 public function setConnectionClass($connectionClass)
103 if (! is_string($connectionClass) && $connectionClass !== null) {
104 throw new Exception\
InvalidArgumentException(sprintf(
105 'Connection class must be a string or null; argument of type "%s" provided',
106 (is_object($connectionClass) ?
get_class($connectionClass) : gettype($connectionClass))
109 $this->connectionClass
= $connectionClass;
114 * Get connection configuration array
118 public function getConnectionConfig()
120 return $this->connectionConfig
;
124 * Set connection configuration array
126 * @param array $connectionConfig
127 * @return SmtpOptions
129 public function setConnectionConfig(array $connectionConfig)
131 $this->connectionConfig
= $connectionConfig;
140 public function getHost()
148 * @todo hostname/IP validation
149 * @param string $host
150 * @return SmtpOptions
152 public function setHost($host)
154 $this->host
= (string) $host;
159 * Get the port the SMTP server runs on
163 public function getPort()
169 * Set the port the SMTP server runs on
172 * @throws \Zend\Mail\Exception\InvalidArgumentException
173 * @return SmtpOptions
175 public function setPort($port)
179 throw new Exception\
InvalidArgumentException(sprintf(
180 'Port must be greater than 1; received "%d"',
191 public function getConnectionTimeLimit()
193 return $this->connectionTimeLimit
;
197 * @param int|null $seconds
200 public function setConnectionTimeLimit($seconds)
202 $this->connectionTimeLimit
= $seconds === null