问题描述
我正在尝试在Controller中编写一个函数,以便通过nextcloud中的应用程序发送电子邮件。这是用于发送电子邮件的SendUserMail函数:
public function sendUserMail($toUserEmail,$organizations,$toDisplayName) {
if (!$toUserEmail || !filter_var($toUserEmail,FILTER_VALIDATE_EMAIL)) {
throw new Exception('Invalid email address (' . $toUserEmail . ')');
}
$emailTemplate = $this->mailer->createEMailTemplate('[email protected]',[
'owner' => 'tester','title' => 'Assign Value','link' => 'http://google.com'
]);
$emailTemplate->setSubject('App - New Activity');
$emailTemplate->addHeader();
$emailTemplate->addHeading('App - New Activity',false);
$emailTemplate->addBodyText('Your details have been updated');
$emailTemplate->addBodyText($variable);
$emailTemplate->addBodyText('Updated results');
$emailTemplate->addFooter('This email is sent to you on behalf of the application. If you want to get removed from this app,contact the site administrator);
try {
$message = $this->mailer->createMessage();
$message->setTo([$toUserEmail => $toDisplayName]);
$message->useTemplate($emailTemplate);
$this->mailer->send($message);
return new Dataresponse(1);
} catch (\Exception $e) {
$this->logger->logException($e);
throw $e;
}
}
该函数直接写在控制器中以进行检查,但是给出了
[HTTP/1.1 405 Method Not Allowed 125ms]
使用axios从vue js前端调用时出错。
我对应用程序开发非常陌生,因此如果有人可以指导我如何创建通过我的应用程序发送电子邮件的功能,我将非常感激。谢谢
编辑1
这里是Vue.js文件,即我正在调用控制器和函数的函数:
async sendMail() {
this.updatingType = true
try {
this.etests.toUserEmail = '[email protected]'
this.etests.organizations = 'test'
this.etests.toDisplayName = 'Tester'
const responseT = await axios.post(OC.generateUrl(`/apps/organization/api/v1/sendMail`,this.etests))
console.log(responseT.data)
} catch (e) {
console.error(e)
}
this.updatingType = false
}
我的路线文件:
<?php
return [
'resources' => [
'note' => ['url' => '/notes'],'type' => ['url' => '/types'],'lang' => ['url' => '/langs'],],'routes' => [
['name' => 'page#index','url' => '/','verb' => 'GET'],['name' => 'DataRequest#sendMail','url' => '/api/v1/sendMail','verb' => 'POST'],]
];
响应标题:
XHRPOST site.com/index.php/apps/organization/eusers/sendUserMail
[HTTP/1.1 405 Method Not Allowed 113ms]
POST
scheme
https
host
site
filename
/index.php/apps/organization/eusers/sendUserMail
Address
18.184.66.60:443
Status405
Method Not Allowed
VersionHTTP/1.1
Transferred1.81 KB (0 B size)
HTTP/1.1 405 Method Not Allowed
Date: Mon,17 Aug 2020 12:25:27 GMT
Server: Apache/2.4.29 (Ubuntu)
Expires: Thu,19 Nov 1981 08:52:00 GMT
Cache-Control: no-store,no-cache,must-revalidate
Pragma: no-cache
Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-R05vcks3SU9xczI4RVpHNnRaU25zemdUbVU0QWRSTCtkc0taeTlpc2grZz06ZHEwYUd1dE0zLzZLVitMNzRLemszQXdrckFwb09XYVpCNHZkb2EzL3pxOD0='; style-src 'self' 'unsafe-inline'; frame-src *; img-src * data: blob:; font-src 'self' data:; media-src *; connect-src *; object-src 'none'; base-uri 'self';
Referrer-Policy: no-referrer
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Robots-Tag: none
X-XSS-Protection: 1; mode=block
Content-Length: 0
Keep-Alive: timeout=5,max=84
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
Accept
application/json,text/plain,*/*
Accept-Encoding
gzip,deflate,br
Accept-Language
en-US,en;q=0.5
Connection
keep-alive
Content-Length
2
Content-Type
application/json;charset=utf-8
Cookie
ocuprigmi569=3cpll44d7rjoe6s0c2rtkp044n; oc_sessionPassphrase=2um4jSRlX8RW6%2F6Uham6EL7VMsg%2F7gTVtx39pEXaP8qr7%2FAPMIudEmmFBhttg9wGnGwpmfRlG2LKOji8FkyEeXNoYY6L3cJo57EJmyuM%2B0pDsxcmDFJaltZq0WBVf108; __Host-nc_sameSiteCookielax=true; __Host-nc_sameSiteCookiestrict=true; nc_username=RichardH; nc_token=Su0p2iUx8Hq9vgU8t0p1EZXEMCCzuj6H; nc_session_id=3cpll44d7rjoe6s0c2rtkp044n
Host
site.com
Origin
site
requesttoken
fGmCVNlum2mUJD4OHY1dNdIP7ddWoWMqSJ6rSwV90u4=:Eh6zZYAs7lqiYk1PSLUeWuY42JM+7RdNOdfvIXAum6k=
User-Agent
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:79.0) Gecko/20100101 Firefox/79.0
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)