Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_mail
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TYPO3
sg_mail
Commits
fefdc1a1
Commit
fefdc1a1
authored
8 years ago
by
Torsten Oppermann
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] New MailTemplateService API
parent
78f816d7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Classes/Service/MailTemplateService.php
+178
-48
178 additions, 48 deletions
Classes/Service/MailTemplateService.php
with
178 additions
and
48 deletions
Classes/Service/MailTemplateService.php
+
178
−
48
View file @
fefdc1a1
...
...
@@ -8,8 +8,6 @@ use TYPO3\CMS\Core\Mail\MailMessage;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Extbase\Object\ObjectManager
;
use
TYPO3\CMS\Fluid\View\StandaloneView
;
use
TYPO3\CMS\Lang\LanguageService
;
use
Typoheads\Formhandler\Finisher\AbstractFinisher
;
/***************************************************************
* Copyright notice
...
...
@@ -45,6 +43,69 @@ class MailTemplateService {
*/
private
static
$registerArray
=
[];
/**
* @var array to
*/
private
$to
=
[];
/**
* @var string from
*/
private
$from
;
/**
* @var string $cc
*/
private
$cc
;
/**
* @var string replyTo
*/
private
$replyTo
;
/**
* @var string language
*/
private
$language
;
/**
* @var boolean ignoreMailQueue
*/
private
$ignoreMailQueue
=
TRUE
;
/**
* @var \TYPO3\CMS\Core\Mail\MailMessage $mailMessage
*/
private
$mailMessage
;
/**
* @var string templateName
*/
private
$templateName
;
/**
* @var string extensionKey
*/
private
$extensionKey
;
/**
* @var array content
*/
private
$content
=
[];
/**
* @var string subject
*/
private
$subject
;
/**
* MailTemplateService constructor.
*/
public
function
__construct
()
{
$objectManager
=
GeneralUtility
::
makeInstance
(
ObjectManager
::
class
);
$this
->
mailMessage
=
$objectManager
->
get
(
MailMessage
::
class
);
}
/**
* register a template with sg_mail
*
...
...
@@ -82,61 +143,36 @@ class MailTemplateService {
}
/**
* send an Email
*
* @param string $language
* @param string $templateKey
* @param string $extensionKey
* @param array $toAddress
* @param array $fromAddress
* @param string $subject
* @param array $content
* @param boolean $ignoreMailQueue
* send the Email
*/
public
static
function
sendEmail
(
$language
,
$templateKey
,
$extensionKey
,
array
$toAddress
,
array
$fromAddress
,
$subject
,
array
$content
,
$ignoreMailQueue
=
FALSE
)
{
// @TODO get language dynamically
!
isset
(
$language
)
?
$language
=
'de'
:
null
;
// Set Email Content
public
function
sendEmail
()
{
$registerArray
=
MailTemplateService
::
getRegisterArray
();
$templateEntry
=
$registerArray
[
$extensionKey
][
$template
Key
];
$templateEntry
=
$registerArray
[
$
this
->
extensionKey
][
$
this
->
template
Name
];
$objectManager
=
GeneralUtility
::
makeInstance
(
ObjectManager
::
class
);
$emailView
=
$objectManager
->
get
(
StandaloneView
::
class
);
$emailView
->
setTemplatePathAndFilename
(
$templateEntry
[
'templatePath'
]
.
$language
.
'.sg_mail.locallang.html'
);
$emailView
->
assignMultiple
(
$content
);
$emailView
->
setTemplatePathAndFilename
(
$templateEntry
[
'templatePath'
]
.
$this
->
language
.
'.sg_mail.locallang.html'
);
$emailView
->
assignMultiple
(
$this
->
content
);
$emailBody
=
$emailView
->
render
();
if
(
$ignoreMailQueue
)
{
$mailMessage
=
$objectManager
->
get
(
MailMessage
::
class
);
$mailMessage
->
setFrom
(
$fromAddress
);
$mailMessage
->
setTo
(
$toAddress
);
$mailMessage
->
setSubject
(
$subject
);
$mailMessage
->
setBody
(
$emailBody
,
'text/html'
);
$mailMessage
->
send
();
if
(
$this
->
ignoreMailQueue
)
{
$this
->
mailMessage
->
setSubject
(
$this
->
subject
);
$this
->
mailMessage
->
setBody
(
$emailBody
,
'text/html'
);
$this
->
mailMessage
->
send
();
}
else
{
// @todo evtl. sollten hier noch die Parameter $priority und $pid mit gegeben werden.
self
::
addMailToMailQueue
(
$fromAddress
,
$toAddress
,
$subject
,
$emailBody
);
$this
->
addMailToMailQueue
(
$emailBody
);
}
}
/**
* Adds a new mail to the mail queue.
This will have the given parameters.
* Adds a new mail to the mail queue.
*
* @param string $fromAddress
* @param string $toAddress
* @param string $mailSubject
* @param string $mailBody
* @param int $priority
* @param int $pid
*/
public
static
function
addMailToMailQueue
(
$fromAddress
,
$toAddress
,
$mailSubject
,
$mailBody
=
''
,
$priority
=
Mail
::
PRIORITY_LOWEST
,
$pid
=
0
)
{
* @param string $emailBody
*/
private
function
addMailToMailQueue
(
$emailBody
,
$priority
=
Mail
::
PRIORITY_LOWEST
,
$pid
=
0
)
{
/** @var ObjectManager $objectManager */
$objectManager
=
GeneralUtility
::
makeInstance
(
ObjectManager
::
class
);
...
...
@@ -146,13 +182,107 @@ class MailTemplateService {
$mail
=
$objectManager
->
get
(
Mail
::
class
);
$mail
->
setPid
(
$pid
);
$mail
->
setFromAddress
(
$
fromAddress
);
$mail
->
setToAddress
(
$t
oAddress
);
$mail
->
setMailSubject
(
$
mailS
ubject
);
$mail
->
setMailBody
(
$mailBody
);
$mail
->
setFromAddress
(
$
this
->
from
);
$mail
->
setToAddress
(
$t
his
->
to
);
$mail
->
setMailSubject
(
$
this
->
s
ubject
);
$mail
->
setMailBody
(
$
e
mailBody
);
$mail
->
setPriority
(
$priority
);
$mailRepository
=
$objectManager
->
get
(
MailRepository
::
class
);
$mailRepository
->
add
(
$mail
);
}
/**
* @param array $registerArray
* @return MailTemplateService
*/
public
static
function
setRegisterArray
(
$registerArray
)
{
self
::
$registerArray
=
$registerArray
;
}
/**
* @param array | string $to
* @return MailTemplateService
*/
public
function
setTo
(
$to
)
{
$this
->
to
=
$to
;
$this
->
mailMessage
->
setTo
(
$to
);
return
$this
;
}
/**
* @param array | string $from
* @return MailTemplateService
*/
public
function
setFrom
(
$from
)
{
$this
->
from
=
$from
;
$this
->
mailMessage
->
setFrom
(
$from
);
return
$this
;
}
/**
* @param array | string $cc
* @return MailTemplateService
*/
public
function
setCc
(
$cc
)
{
$this
->
cc
=
$cc
;
$this
->
mailMessage
->
setCc
(
$cc
);
return
$this
;
}
/**
* @param array | string $replyTo
* @return MailTemplateService
*/
public
function
setReplyTo
(
$replyTo
)
{
$this
->
replyTo
=
$replyTo
;
$this
->
mailMessage
->
setReplyTo
(
$replyTo
);
return
$this
;
}
/**
* @param string $language
* @return MailTemplateService
*/
public
function
setLanguage
(
$language
)
{
$this
->
language
=
$language
;
return
$this
;
}
/**
* @param boolean $ignoreMailQueue
* @return MailTemplateService
*/
public
function
setIgnoreMailQueue
(
$ignoreMailQueue
)
{
$this
->
ignoreMailQueue
=
$ignoreMailQueue
;
return
$this
;
}
/**
* @param string $templateName
* @return MailTemplateService
*/
public
function
setTemplateName
(
$templateName
)
{
$this
->
templateName
=
$templateName
;
return
$this
;
}
/**
* @param string $extensionKey
* @return MailTemplateService
*/
public
function
setExtensionKey
(
$extensionKey
)
{
$this
->
extensionKey
=
$extensionKey
;
return
$this
;
}
/**
* @param string $subject
* @return MailTemplateService
*/
public
function
setSubject
(
$subject
)
{
$this
->
subject
=
$subject
;
$this
->
mailMessage
->
setSubject
(
$subject
);
return
$this
;
}
}
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