Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Quickbuild Send Email via 'Execute Script Step' NullPointer on sendMail() #4293

aorgas ·

Hello,

I am getting an error in trying to send an email from a Misc -> Execute Script step with the error of: "is failed: java.lang.NullPointerException: Cannot invoke method sendMail() on null object"

Unsure why its saying the MsicUtils is null, but below is the script to execute it:

groovy:
import com.pmease.quickbuild.util.Util
import com.pmease.quickbuild.entitymanager.*

File f = new File("\Path_To_Directory\Files");
File[] fileList = f.listFiles();
if(fileList != null){
for(File indexedFile : fileList){
int count = 0;
String var1 = "";
def usersAffected = [];
def FilesAffected = [];
def lines = indexedFile.readLines();
lines.each{ String line ->
if(count == 0){
Module = line;
}
else if(count == 1){
String[] Tokens = line.split(" ");
for(int a = 0; a < Tokens.length; a++){
usersAffected.add(Tokens[a]);
}
}
else if(count == 2){
String[] Tokens = line.split(" ");
for(int a = 0; a < Tokens.length; a++){
FilesAffected.add(Tokens[a]);
}
}
count++;
}
def attachments = []
def emailSetting = SettingManager.instance.getEmailSetting()
logger.info(usersAffected[0]);
logger.info(FilesAffected[0]);
logger.info("Before sending email.")
MiscUtils.sendMail(usersAffected.join(","), "Mainline Branch Sync Verifier", "Differences in files: " + FilesAffected.join(","), attachments, emailSetting)
}
}

Note: I append the ending of the email under usersAffected, just did not display it in the coode.

I am using QB 10.0

Thanks in Advance!

  • solved #5
  • replies 5
  • views 2464
  • stars 0
Laba42 ·

I think you must declare the varibales **usersAffected **and **FilesAffected ** before the for loop

...
def usersAffected = [];
def FilesAffected = [];
for(File indexedFile : fileList){
	int count = 0;
	String var1 = "";
aorgas ·

Any reason why? Re-declaring the variables inside the for loop should not be a problem because it stays in memory and becomes destroyed/reused after each loop.

Plus, I have it printing out the result of defined string arrays and they are existing (I print it out in the logger.)

aorgas ·

I found the issue, my import of 'com.please.quickbuild.util.Util' was incorrect, it should've been a level below, now the issue is the fact that sendMail() now contains a different syntax.

robinshen ADMIN ·

It requires an additional argument "mimeType", for instance:

MiscUtils.sendMail(usersAffected.join(","), "Mainline Branch Sync Verifier", "Differences in files: " + FilesAffected.join(","), attachments, emailSetting, "text/html")
aorgas ·

Thanks Robin, fixes my issue! :)