0
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)

我收到以下错误

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.c,
string, { text: string } / 'c.e -> 'a.
Types string and { none } / { some: string } are not compatible
Hint:
  Error occurred through field name.

任何人都可以帮助我使用 Opa 中的邮件功能吗?

4

1 回答 1

2

这段代码有很多问题:

  • 请注意,在Email.email类型中,该name字段是可选的;所以如果你想包含它,你应该提供some("name"),而不仅仅是"name"
  • Server.one_page_server包含 2 个参数而不是 4 个。
  • 最后一个参数one_page_server应该是xhtml页面的,而你r的是发送电子邮件的结果。

在这些修复之后,您的代码可能看起来像这样:

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)
于 2011-09-23T11:51:44.950 回答