Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
cd8da302
Commit
cd8da302
authored
5 years ago
by
Bryce Lowe
Browse files
Options
Downloads
Patches
Plain Diff
added ability to select different mail transport options
parent
50522556
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config-templates/config.php
+31
-0
31 additions, 0 deletions
config-templates/config.php
lib/SimpleSAML/Utils/EMail.php
+99
-0
99 additions, 0 deletions
lib/SimpleSAML/Utils/EMail.php
with
130 additions
and
0 deletions
config-templates/config.php
+
31
−
0
View file @
cd8da302
...
...
@@ -75,6 +75,37 @@ $config = [
'technicalcontact_name'
=>
'Administrator'
,
'technicalcontact_email'
=>
'na@example.org'
,
/*
* (Optional) The method by which email is delivered. Defaults to mail which utilizes the
* PHP mail() function.
*
* Valid options are: mail, sendmail and smtp.
*/
//'mail.transport.method' => 'smtp',
/*
* Set the transport options for the transport method specified. The valid settings are relative to the
* selected transport method.
*/
//// smtp mail transport options
// 'mail.transport.options' => [
// 'host' => 'mail.example.org',
// 'port' => 25,
// 'username' => 'user@example.org', 'password' => '',
// 'security' => 'tls',
// ],
//// sendmail mail transport options
// 'mail.transport.options' => [
// 'path' => '/usr/sbin/sendmail'
// ],
/*
* (Optional) When using the Sendmail transport method, provide an alternate path to the Sendmail
* executable.
*/
//'mail.sendmail.path' => '',
/*
* The envelope from address for outgoing emails.
* This should be in a domain that has your application's IP addresses in its SPF record
...
...
This diff is collapsed.
Click to expand it.
lib/SimpleSAML/Utils/EMail.php
+
99
−
0
View file @
cd8da302
...
...
@@ -47,6 +47,8 @@ class EMail
$this
->
mail
->
Subject
=
$subject
;
$this
->
mail
->
setFrom
(
$from
?:
static
::
getDefaultMailAddress
());
$this
->
mail
->
addAddress
(
$to
?:
static
::
getDefaultMailAddress
());
static
::
initFromConfig
(
$this
);
}
...
...
@@ -143,6 +145,103 @@ class EMail
$this
->
mail
->
send
();
}
/**
* Sets the method by which the email will be sent. Currently supports what
* PHPMailer supports: sendmail, mail and smtp.
*
* @param string $transportMethod the transport method
* @param array $transportOptions options for the transport method
*
* @return void
*
* @throws \InvalidArgumentException
*/
public
function
setTransportMethod
(
$transportMethod
,
array
$transportOptions
=
[])
{
assert
(
is_string
(
$transportMethod
));
assert
(
is_array
(
$transportOptions
));
switch
(
strtolower
(
$transportMethod
))
{
// smtp transport method
case
'smtp'
:
$this
->
mail
->
isSMTP
();
// set the host (required)
if
(
isset
(
$transportOptions
[
'host'
]))
{
$this
->
mail
->
Host
=
$transportOptions
[
'host'
];
}
// throw an exception otherwise
else
{
throw
new
\InvalidArgumentException
(
"Missing Required Email Transport Parameter 'host'"
);
}
// set the port (optional, assume standard SMTP port 25 if not provided)
$this
->
mail
->
Port
=
(
isset
(
$transportOptions
[
'port'
]))
?
(
int
)
$transportOptions
[
'port'
]
:
25
;
// smtp auth: enabled if username or password is set
if
(
isset
(
$transportOptions
[
'username'
])
||
isset
(
$transportOptions
[
'password'
]))
{
$this
->
mail
->
SMTPAuth
=
true
;
}
// smtp auth: username
if
(
isset
(
$transportOptions
[
'username'
]))
{
$this
->
mail
->
Username
=
$transportOptions
[
'username'
];
}
// smtp auth: password
if
(
isset
(
$transportOptions
[
'password'
]))
{
$this
->
mail
->
Password
=
$transportOptions
[
'password'
];
}
// smtp security: encryption type
if
(
isset
(
$transportOptions
[
'secure'
]))
{
$this
->
mail
->
SMTPSecure
=
$transportOptions
[
'secure'
];
}
// smtp security: enable or disable smtp auto tls
if
(
isset
(
$transportOptions
[
'autotls'
]))
{
$this
->
mail
->
SMTPAutoTLS
=
(
bool
)
$transportOptions
[
'autotls'
];
}
break
;
//mail transport method
case
'mail'
:
$this
->
mail
->
isMail
();
break
;
// sendmail transport method
case
'sendmail'
:
$this
->
mail
->
isSendmail
();
// override the default path of the sendmail executable
if
(
isset
(
$transportOptions
[
'path'
]))
{
$this
->
mail
->
Sendmail
=
$transportOptions
[
'path'
];
}
break
;
default
:
throw
new
\InvalidArgumentException
(
"Invalid Mail Transport Method - Check 'mail.transport.method' Configuration Option"
);
}
}
/**
* Initializes the provided EMail object with the configuration provided from the SimpleSAMLphp configuration.
*
* @param EMail $EMail
* @return EMail
* @throws \Exception
*/
public
static
function
initFromConfig
(
EMail
$EMail
)
{
assert
(
$EMail
instanceof
EMail
);
$config
=
Configuration
::
getInstance
();
$EMail
->
setTransportMethod
(
$config
->
getString
(
'mail.transport.method'
,
''
),
$config
->
getArrayize
(
'mail.transport.options'
,
[])
);
return
$EMail
;
}
/**
* Generate the body of the e-mail
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment