function renderAndSendEmail(emailAddress, results, baseUrl, mailCredentials, oneTimeCode) {
  // The oneTimeCode is important, it's used to generate a unique unsubscribe link. It can be used multiple times but times out after a day
  console.log('Using one-time code of: %s', oneTimeCode)
  const transporter = nodemailer.createTransport({
    host: mailCredentials.host,
    port: 465,  // Secure SMTP, change this to 25 if 465 isn't allowed. Not recommended in general.
    secure: true,
    attachDataUrls: true,  // Allows embedding of images in the emails which was used with rendered charts
    auth: {
      user: mailCredentials.user,
      pass: mailCredentials.pass
    }
  })

  // The StaticRouter is used in case there are requirements to change the email style per type of email being sent
  const context = {}
  const renderedBody = ReactDOMServer.renderToString(
    <html>
      <head>
      </head>
      <body>
        <StaticRouter
          location='/news-alert'
          context={context}>
          <Email baseUrl={baseUrl} results={results} oneTimeCode={oneTimeCode} />
        </StaticRouter>
      </body>
    </html>
  )

  const mailOptions = {
    from: `"Watson Discovery Alerts" <${mailCredentials.fromEmail}>`,
    to: emailAddress,
    subject: 'Watson Discovery News Update',
    text: 'Unfortunately, these emails require HTML to be enabled in order to view them.',
    html: renderedBody
  }

  transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
      return console.error(error)
    }
    console.log('Message %s sent: %s', info.messageId, info.response)
  })
}
// from dealing with limitations using a mail relay and recording metrics on mails delivered.
from dealing with limitations using a mail relay and recording metrics on mails delivered.
from dealing with limitations using a mail relay and recording metrics on mails delivered .
function renderAndSendEmail(emailAddress, results, baseUrl, mailCredentials, oneTimeCode) {
  console.log('Using one-time code of: %s', oneTimeCode)
  const transporter = nodemailer.createTransport({
    host: mailCredentials.host,
    port: 465,  
    secure: true,
    attachDataUrls: true,  
    auth: {
      user: mailCredentials.user,
      pass: mailCredentials.pass
    }
  })
  const context = {}
  const renderedBody = ReactDOMServer.renderToString(
    <html>
      <head>
      </head>
      <body>
        <StaticRouter
          location='/news-alert'
          context={context}>
          <Email baseUrl={baseUrl} results={results} oneTimeCode={oneTimeCode} />
        </StaticRouter>
      </body>
    </html>
  )
  const mailOptions = {
    from: `"Watson Discovery Alerts" <${mailCredentials.fromEmail}>`,
    to: emailAddress,
    subject: 'Watson Discovery News Update',
    text: 'Unfortunately, these emails require HTML to be enabled in order to view them.',
    html: renderedBody
  }
  transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
      return console.error(error)
    }
    console.log('Message %s sent: %s', info.messageId, info.response)
  })
}
function renderAndSendEmail ( emailAddress , results , baseUrl , mailCredentials , oneTimeCode ) { console . log ( 'Using one-time code of: %s' , oneTimeCode ) const transporter = nodemailer . createTransport ( { host : mailCredentials . host , port : 465 , secure : true , attachDataUrls : true , auth : { user : mailCredentials . user , pass : mailCredentials . pass } } ) const context = { } const renderedBody = ReactDOMServer . renderToString ( < html > < head > < / head > < body > < StaticRouter location = '/news-alert' context = { context } > < Email baseUrl = { baseUrl } results = { results } oneTimeCode = { oneTimeCode } / > < / StaticRouter > < / body > < / html > ) const mailOptions = { from : ` ${ mailCredentials . fromEmail } ` , to : emailAddress , subject : 'Watson Discovery News Update' , text : 'Unfortunately, these emails require HTML to be enabled in order to view them.' , html : renderedBody } transporter . sendMail ( mailOptions , ( error , info ) => { if ( error ) { return console . error ( error ) } console . log ( 'Message %s sent: %s' , info . messageId , info . response ) } ) }
from dealing with limitations using a mail relay and recording metrics on mails delivered.
from dealing with limitations using a mail relay and recording metrics on mails delivered .
// The oneTimeCode is important, it's used to generate a unique unsubscribe link. It can be used multiple times but times out after a day // Secure SMTP, change this to 25 if 465 isn't allowed. Not recommended in general. // Allows embedding of images in the emails which was used with rendered charts // The StaticRouter is used in case there are requirements to change the email style per type of email being sent