Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
TYPO3
sg_mail
Commits
c5b54ac9
Commit
c5b54ac9
authored
Sep 18, 2016
by
Torsten Oppermann
Browse files
[TASK] Implementing test Email
parent
711ba69b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Classes/Controller/MailController.php
View file @
c5b54ac9
...
...
@@ -151,7 +151,6 @@ class MailController extends ActionController {
$contentLeft
=
NULL
,
$contentRight
=
NULL
,
$selectedExtension
=
NULL
,
$selectedTemplate
=
NULL
,
$extensionKey
=
NULL
,
$selectedLanguageLeft
=
NULL
,
$selectedLanguageRight
=
NULL
)
{
$arguments
=
$this
->
request
->
getArguments
();
$templatePath
=
$this
->
getTemplatePath
(
$selectedExtension
,
$selectedTemplate
);
...
...
@@ -161,10 +160,10 @@ class MailController extends ActionController {
$filename
=
$templatePath
.
$selectedLanguageRight
.
'.sg_mail.locallang.html'
;
file_put_contents
(
$filename
,
$contentRight
);
$label
=
'backend.success'
;
$message
=
LocalizationUtility
::
translate
(
$label
,
'SgMail'
);
$message
=
LocalizationUtility
::
translate
(
'backend.success'
,
'SgMail'
);
$this
->
addFlashMessage
(
$message
,
''
,
FlashMessage
::
OK
);
$arguments
=
$this
->
request
->
getArguments
();
$this
->
redirect
(
'index'
,
NULL
,
NULL
,
$arguments
);
}
...
...
@@ -190,4 +189,39 @@ class MailController extends ActionController {
return
$templatePath
;
}
/**
* send a test email to a given address
* redirect to index action
*
* @param string $emailAddress
* @param string $templateKey
* @param string $extensionKey
* @param string $languageLeft
* @param string $languageRight
*/
public
function
sendTestMailAction
(
$emailAddress
=
NULL
,
$selectedExtensionKey
=
NULL
,
$selectedTemplateKey
=
NULL
,
$selectedLanguageLeft
=
NULL
,
$selectedLanguageRight
=
NULL
)
{
// empty content array for test mails
$content
=
[];
MailTemplateService
::
sendEmail
(
$selectedLanguageLeft
,
$selectedTemplateKey
,
$selectedExtensionKey
,
$emailAddress
,
'test@sgmail.de'
,
'This is just a Test E-Mail'
,
$content
);
MailTemplateService
::
sendEmail
(
$selectedLanguageRight
,
$selectedTemplateKey
,
$selectedExtensionKey
,
$emailAddress
,
'test@sgmail.de'
,
'This is just a Test E-Mail'
,
$content
);
$message
=
LocalizationUtility
::
translate
(
'backend.success_mail'
,
'SgMail'
);
$this
->
addFlashMessage
(
$message
,
''
,
FlashMessage
::
OK
);
$arguments
=
$this
->
request
->
getArguments
();
$this
->
redirect
(
'index'
,
NULL
,
NULL
,
$arguments
);
}
}
Classes/Service/MailTemplateService.php
View file @
c5b54ac9
...
...
@@ -2,6 +2,8 @@
namespace
SGalinski\SgMail\Service
;
use
\
TYPO3\CMS\Core\Utility\GeneralUtility
;
/***************************************************************
* Copyright notice
*
...
...
@@ -66,4 +68,46 @@ class MailTemplateService {
public
static
function
getRegisterArray
()
{
return
self
::
$registerArray
;
}
/**
* @param string $language
* @param string $templateKey
* @param string $extensionKey
* @param string $toAddress
* @param string $fromAddress
* @param string $subject
* @param string $content
*/
public
static
function
sendEmail
(
$language
,
$templateKey
,
$extensionKey
,
$toAddress
,
$fromAddress
,
$subject
,
array
$content
)
{
// Set Email Content
$registerArray
=
MailTemplateService
::
getRegisterArray
();
$templateEntry
=
$registerArray
[
$extensionKey
][
$templateKey
];
$templateFileContents
=
file_get_contents
(
$templateEntry
[
'templatePath'
]
.
$language
.
'.sg_mail.locallang.html'
);
$body
=
$templateFileContents
;
$mail
=
GeneralUtility
::
makeInstance
(
'TYPO3\\CMS\\Core\\Mail\\MailMessage'
);
$mail
->
setFrom
(
$fromAddress
);
$mail
->
setTo
(
$toAddress
);
$mail
->
setSubject
(
$subject
);
$mail
->
setBody
(
$body
);
$mail
->
send
();
}
/**
* injects content into template
*
* @param string $templateContent
* @param array $marker
* @return string
*/
private
static
function
injectEmailContent
(
$templateContent
,
array
$content
)
{
# @TODO inject content
return
''
;
}
}
Resources/Private/Language/de.locallang.xlf
View file @
c5b54ac9
...
...
@@ -25,12 +25,20 @@
<source>
Select Language
</source>
<target>
Sprache auswählen
</target>
</trans-unit>
<trans-unit
id=
"backend.send_test"
approved=
"yes"
>
<source>
Send Test E-Mail
</source>
<target>
Test E-Mail versenden
</target>
</trans-unit>
<trans-unit
id=
"backend.success"
approved=
"yes"
>
<source>
Successfully saved !
</source>
<target>
Erfolgreich gespeichert !
</target>
</trans-unit>
<trans-unit
id=
"backend.success_mail"
approved=
"yes"
>
<source>
Test E-Mail sent
</source>
<target>
Test E-Mail wurde versendet
</target>
</trans-unit>
<trans-unit
id=
"backend.template_path"
approved=
"yes"
>
<source>
Template Path:
</source>
<source>
Template Path:
</source>
<target>
Pfad:
</target>
</trans-unit>
<trans-unit
id=
"backend.value"
approved=
"yes"
>
...
...
Resources/Private/Language/locallang.xlf
View file @
c5b54ac9
...
...
@@ -21,11 +21,17 @@
<trans-unit
id=
"backend.select_language"
>
<source>
Select Language
</source>
</trans-unit>
<trans-unit
id=
"backend.send_test"
>
<source>
Send Test E-Mail
</source>
</trans-unit>
<trans-unit
id=
"backend.success"
>
<source>
Successfully saved !
</source>
</trans-unit>
<trans-unit
id=
"backend.success_mail"
>
<source>
Test E-Mail sent
</source>
</trans-unit>
<trans-unit
id=
"backend.template_path"
>
<source>
Template Path:
</source>
<source>
Template Path:
</source>
</trans-unit>
<trans-unit
id=
"backend.value"
>
<source>
Value
</source>
...
...
Resources/Private/Templates/Mail/Index.html
View file @
c5b54ac9
...
...
@@ -24,6 +24,17 @@
</tr>
</f:for>
</table>
<f:form
method=
"post"
controller=
"Mail"
action=
"sendTestMail"
>
<f:form.textfield
name=
"emailAddress"
type=
"email"
required=
"TRUE"
class=
"form-group"
/>
<f:form.hidden
name=
"selectedLanguageLeft"
value=
"{selectedLanguageLeft}"
></f:form.hidden>
<f:form.hidden
name=
"selectedLanguageRight"
value=
"{selectedLanguageRight}"
></f:form.hidden>
<f:form.hidden
name=
"selectedTemplate"
value=
"{selectedTemplateKey}"
></f:form.hidden>
<f:form.hidden
name=
"selectedExtensionKey"
value=
"{selectedTemplate.extension}"
></f:form.hidden>
<f:form.hidden
name=
"selectedExtension"
value=
"{selectedTemplate.extension}"
></f:form.hidden>
<f:form.hidden
name=
"selectedTemplateKey"
value=
"{selectedTemplateKey}"
></f:form.hidden>
<f:form.submit
class=
"btn-primary btn form-group"
value=
"{f:translate(key:'backend.send_test')}"
/>
</f:form>
<f:form
method=
"post"
controller=
"Mail"
action=
"save"
>
<div
class=
"col-md-6 form-group"
>
<div
class=
"form-group"
>
...
...
@@ -92,4 +103,5 @@
<f:form.submit
class=
"col-md-6 btn-success btn"
value=
"{f:translate(key:'backend.save')}"
/>
</div>
</f:form>
</f:section>
ext_localconf.php
View file @
c5b54ac9
...
...
@@ -45,10 +45,10 @@ $marker = [
]
];
$description
=
'
This is just a Test Email
'
;
$description
=
'
E-Mail for Passwort reset request
'
;
\
SGalinski\SgMail\Service\MailTemplateService
::
registerTemplate
(
'sg_mail'
,
'
system test email
'
,
$templatePath
,
$description
,
$marker
'sg_mail'
,
'
password_reset
'
,
$templatePath
,
$description
,
$marker
);
$templatePath
=
$extPath
.
'Resources/Private/'
;
...
...
@@ -66,10 +66,10 @@ $marker = [
]
];
$description
=
'
This is just a another Test Email
'
;
$description
=
'
E-Mail for confirmation of registration process
'
;
\
SGalinski\SgMail\Service\MailTemplateService
::
registerTemplate
(
'sg_mail'
,
'
system another test email
'
,
$templatePath
,
$description
,
$marker
'sg_mail'
,
'
registration_confirmation
'
,
$templatePath
,
$description
,
$marker
);
if
(
TYPO3_MODE
===
'BE'
)
{
...
...
ext_tables.php
View file @
c5b54ac9
...
...
@@ -10,7 +10,7 @@ if (!defined('TYPO3_MODE')) {
'Mail'
,
''
,
[
'Mail'
=>
'index, s
howTemplate, showMarker, saveMarker
'
,
'Mail'
=>
'index, s
ave, sendTestMail
'
,
],
[
'access'
=>
'admin,user,group'
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment