Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import nodemailer from "nodemailer";
- var nodeMailer = require("nodemailer");
- class ContactAdmin extends React.Component {
- constructor(props) {
- super(props);
- }
- render() {
- return (
- <h3>Kontakt admin</h3>
- </div>
- <div>
- <input type="email" placeholder="Din email" ref="yourEmail" />
- <br />
- <input type="text" placeholder="Emne" ref="subject" />
- <br />
- <textarea
- placeholder="Skriv inn meldingen din her"
- ref="contentEmail"
- rows="4"
- cols="19"
- />
- <br />
- <button
- type="button"
- id="contactAdminButton"
- className="btn btn-primary"
- ref="sendEmail"
- >
- Send
- </button>
- </div>
- </div>
- );
- }
- componentDidMount() {
- this.refs.backToMainScreenButton.onclick = () => {
- history.replace("/mainScreen");
- };
- this.refs.sendEmail.onclick = () => {
- let transporter = nodeMailer.createTransport({
- host: "smtp.gmail.com",
- port: 465,
- secure: true,
- auth: {
- user: "dinmail@gmail.com",
- pass: "dittpassord"
- }
- });
- let mailOptions = {
- from: this.refs.yourEmail.value, // sender address
- to: "dinmail@gmail.com", // list of receivers
- subject: this.refs.subject.value, // Subject line
- html:
- this.refs.contentEmail.value +
- "<br>" +
- "</br>" +
- "Du har mottatt denne meldingen fra " +
- this.refs.yourEmail.value // plain text body
- };
- transporter.sendMail(mailOptions, (error, info) => {
- if (error) {
- return console.log(error);
- }
- });
- history.replace("/emailConfirmation/");
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement