Hi ramitaherwahd...,
Refer the following steps.
Create a new Angular application using the following command.
ng new angular-email-app
cd angular-email-app
ng serve
Import the ReactiveFormsModule into your AppModule.
import { ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [ReactiveFormsModule],
})
export class AppModule {}
Create a form component.
import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms';
export class EmailFormComponent implements OnInit {
FormData: FormGroup;
constructor(private builder: FormBuilder) {}
ngOnInit() {
this.FormData = this.builder.group({
EmailAddress: new FormControl('', [Validators.compose([Validators.required, Validators.email])]),
Body: new FormControl('', [Validators.required]),
});
}
}
To send emails from the front end.
In your email-form.component.ts, create a function that sends the email.
submitEmail() {
const emailData = {
to: 'recipient@example.com',
subject: 'Your Subject',
body: this.FormData.value.Body,
};
}
To add an attachment, you will need to handle file uploads and include the attachment data in your email request.
Modify the submitEmail function to include the attachment.
submitEmail() {
const emailData = {
to: 'recipient@example.com',
subject: 'Your Subject',
body: this.FormData.value.Body,
attachment: 'base64-encoded-file-content'
};
}