开发者

Mail functionality using OPA

import stdlib.web.mail

from = {name="name" address={local="username" domain="gmail.com"}}
to = {name="name" address={local="username" domain="gmail.com"}}

r = Email.try_send(from, to, "Subject", {text = "This is Great!"})

server = Server.one_page_server("Mail", [], [], r)

the following error I'm getting

Error
File "mail.opa", line 6, characters 4-66, (6:4-6:66 | 166-228)
Function was found of type
Email.email, Email.email, string, Email.content -> Email.send_status but
application expects it to be of type
{ address: { domain: string; local: string } / 'c.b; name: string } / 'c.a,
{ address: { domain: string; local: string } / 'c.d; name: string } / 'c.开发者_JAVA技巧c,
string, { text: string } / 'c.e -> 'a.
Types string and { none } / { some: string } are not compatible
Hint:
  Error occurred through field name.

Can anyone help me with Mail functionality in Opa?


There is a number of problems with this code:

  • Notice that in Email.email type the name field is optional; so if you want to include it you should provide some("name"), not just "name"
  • Server.one_page_server contains 2 arguments not 4.
  • The last argument to one_page_server should be the xhtml of the page, whereas your r is the result of sending an email.

After those fixes your code could look something like this:

import stdlib.web.mail

from = {name=some("name") address={local="username" domain="gmail.com"}} : Email.email
to = {name=some("name") address={local="username" domain="gmail.com"}} : Email.email

page() =
  status = Email.try_send(from, to, "Subject", {text = "This is Great!"})
  <>Email sent</>

server = Server.one_page_server("Mail", page)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜