使用 <h:commandButton> 打开 Outlook

ahm*_*l88 0 email jsf outlook hyperlink

对应的JSF代码是什么

<a href="mailto:me@domain.com?subject=Sample subject&body=test&cc=cc@domain.com">Send mail</a>
Run Code Online (Sandbox Code Playgroud)

使用预填充的邮件模板向用户打开 Outlook 邮箱?

Bal*_*usC 6

假设您使用的是 JSF 1.2 或更新版本,您可以在 JSF 页面中使用完全相同的 HTML 代码。

<a href="mailto:me@domain.com?subject=Sample subject&body=test&cc=cc@domain.com">Send mail</a>
Run Code Online (Sandbox Code Playgroud)

如果您打算根据 JSF 表单中的值预填充它,那么您需要将重定向发送到该 URL。

public void submit() throws IOException {
    // ...

    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    externalContext.redirect(String.format(
        "mailto:me@domain.com?subject=%s&body=%s&cc=cc@domain.com",
            URLEncoder.encode(subject, "UTF-8"),
            URLEncoder.encode(body, "UTF-8")));
}
Run Code Online (Sandbox Code Playgroud)

请注意,这不一定会在 Outlook 中准备邮件。它只是在客户端自己的默认邮件客户端中准备邮件,它本身可能不是 Outlook。例如,它可能是 Thunderbird 甚至 Gmail。另请注意,您无法控制该部分。