added passreset and mail helper
This commit is contained in:
		
							
								
								
									
										64
									
								
								src/helpers/mail.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								src/helpers/mail.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,64 @@
 | 
			
		||||
import axios from 'axios';
 | 
			
		||||
 | 
			
		||||
// sends an email
 | 
			
		||||
 | 
			
		||||
export default (mailAddress, subject, content, f) => {  // callback, executed empty or with error
 | 
			
		||||
  if (process.env.NODE_ENV === 'production') {
 | 
			
		||||
    const mailService = JSON.parse(process.env.VCAP_SERVICES).Mail[0];
 | 
			
		||||
    axios({
 | 
			
		||||
      method: 'post',
 | 
			
		||||
      url: mailService.credentials.uri + '/email',
 | 
			
		||||
      auth: {username: mailService.credentials.username, password: mailService.credentials.password},
 | 
			
		||||
      data: {
 | 
			
		||||
        recipients: [{to: mailAddress}],
 | 
			
		||||
        subject: {content: subject},
 | 
			
		||||
        body: {
 | 
			
		||||
          content: content,
 | 
			
		||||
          contentType: "text/html"
 | 
			
		||||
        },
 | 
			
		||||
        from: {
 | 
			
		||||
          eMail: "dfop@bosch-iot.com",
 | 
			
		||||
          password: "PlasticsOfFingerprintDigital"
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
      .then(() => {
 | 
			
		||||
        f();
 | 
			
		||||
      })
 | 
			
		||||
      .catch((err) => {
 | 
			
		||||
        f(err);
 | 
			
		||||
      });
 | 
			
		||||
  }
 | 
			
		||||
  else if (process.env.NODE_ENV === 'test') {
 | 
			
		||||
    console.log('Sending mail to ' + mailAddress + ':  -- ' + subject + ' -- ' + content);
 | 
			
		||||
    f();
 | 
			
		||||
  }
 | 
			
		||||
  else {  // dev
 | 
			
		||||
    axios({
 | 
			
		||||
      method: 'get',
 | 
			
		||||
      url: 'https://digital-fingerprint-of-plastics-mail-test.apps.de1.bosch-iot-cloud.com/api',
 | 
			
		||||
      data: {
 | 
			
		||||
        method: 'post',
 | 
			
		||||
        url: '/email',
 | 
			
		||||
        data: {
 | 
			
		||||
          recipients: [{to: mailAddress}],
 | 
			
		||||
          subject: {content: subject},
 | 
			
		||||
          body: {
 | 
			
		||||
            content: content,
 | 
			
		||||
            contentType: "text/html"
 | 
			
		||||
          },
 | 
			
		||||
          from: {
 | 
			
		||||
            eMail: "dfop-test@bosch-iot.com",
 | 
			
		||||
            password: "PlasticsOfFingerprintDigital"
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
      .then(() => {
 | 
			
		||||
        f();
 | 
			
		||||
      })
 | 
			
		||||
      .catch((err) => {
 | 
			
		||||
        f(err);
 | 
			
		||||
      });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user