Mok*_*oru 4 email scripting typescript angular
我现在正在使用Angular7,开始开发应用程序,我想知道如何从angular7应用程序发送电子邮件。请分享示例代码
小智 17
您可以使用一些 BaaS(后端即服务)提供商,例如Formspree。它使用起来非常简单,使您无需编写或设置后端即可发送电子邮件。您所要做的就是从您的 Angular 应用程序发布一个 Http 请求,该服务会负责其余的工作。
然后,您将获得这个新创建的表单的唯一端点,您可以使用该端点从 angular 应用程序发送(发布)电子邮件。端点将如下所示:https://formspree.io/asdlf7asdf
下面是一些使用模板驱动表单的示例代码:
<form (ngSubmit)="onSubmit(contactForm)" #contactForm="ngForm">
<input type="text" placeholder="Name" name="name" ngModel required #name="ngModel">
<input type="text" placeholder="Email" email name="email" ngModel required #email="ngModel">
<textarea placeholder="Messages" name="messages" ngModel required #messages="ngModel"></textarea>
<input type="submit" value="Send">
</form>
Run Code Online (Sandbox Code Playgroud)
onSubmit(contactForm: NgForm) {
if (contactForm.valid) {
const email = contactForm.value;
const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
this.http.post('https://formspree.io/asdlf7asdf',
{ name: email.name, replyto: email.email, message: email.messages },
{ 'headers': headers }).subscribe(
response => {
console.log(response);
}
);
}
}
Run Code Online (Sandbox Code Playgroud)
你可以用这个(或其他)服务做更多的事情,但这将是它的基本要点。
| 归档时间: |
|
| 查看次数: |
12445 次 |
| 最近记录: |