RPA - MailSendOptions attachment throwing null error

Certified Lead Developer

Hi,

I am trying to configure an RPA bot to send a csv file via email.  I have the bot working fine sending an email *without* an attachment, but when I try to add an attachment, I am receiving the following error:

[WARN] 2020-10-07 02:51:55 01m 31s (0h) - Error sending email
java.lang.IllegalArgumentException: Attachment 'testcsv.csv' file cannot be null

My sendEmail() method is below.  I have done the proper (I think) imports above in my file, and have declared the following in my main MyRobot class:

private File currentItemOutputFile;
private IMail mail;

sendEmail() method:

public void sendEmail() throws Exception{
		windows.pause(PAUSE_LONG);
		String subject = "Test Email";
		String body = String.format("Test");
		MailSendOptions message = new MailSendOptions();

		message.setHost("localhost");
		message.setPort(25);
		message.setFromAddress("test@example.com");


		// Adds content to email
		message.toAddress(emailAddress);
		message.setSubject(subject);
		message.setTextContent(body);
		// Attaches file to email
		MailAttachment mailAttachment = new MailAttachment();
		mailAttachment.setType(MailAttachment.EType.FILE);
		mailAttachment.setName(currentItemOutputFile.getName());
		message.setAttachments(mailAttachment);

		try {
			mail.sendMailFromServer(message);
		} catch (Throwable e) {
			server.warn("Error sending email", e);
			throw new JidokaItemException(String.format("Error sending file %s by + email", currentItemOutputFile.getAbsolutePath()));
		}
		// Sends result to server
		server.setCurrentItemResultToOK("Document Sent");
}

  Discussion posts and replies are publicly visible