Quantcast
Channel: PTC Community : All Content - Windchill
Viewing all articles
Browse latest Browse all 6049

Sending Email through code

$
0
0

Hi,

 

I have been trying to send email through code.And I'm getting problem while adding

content text to my mail.If I run my code without adding message body, it works fine and I have

doubts on adding ResourceBundle files here.

 

I've created a simple class for that

 

RemoteMethodServer rms = RemoteMethodServer.getDefault();
GatewayAuthenticator auth = new GatewayAuthenticator();
auth.setRemoteUser("wcadmin");
rms.setAuthenticator(auth);
System.out.println("Connected to PDMLink!");  
String userName="GT-User";
WTUser user;
QuerySpec qspec=new QuerySpec(WTUser.class);
qspec.appendWhere(new SearchCondition(WTUser.class,WTUser.NAME,SearchCondition.LIKE,userName),newint[]{0});
QueryResult qresult=PersistenceHelper.manager.find((StatementSpec)qspec);while(qresult.hasMoreElements()){            user=(WTUser) qresult.nextElement();            System.out.println("User present in Windchill and his email id is--"+user.getEMail());            String userEmail=user.getEMail();//          TeamCommands.email(arg0);             Locale locale=new Locale("en", "US");             ResourceBundle labels=ResourceBundle.getBundle("ext.gt.test.MyResources",locale);              EMailMessage mail=EMailMessage.newEMailMessage();             mail.setSubject("For Windchill test");             mail.addRecipient(user);             mail.addPart("ext.gt.test.MyResources", labels.getString("Message"), null, "text/html");             EMailMessage.fetchUserFromEmailAddress(userName);             boolean ok=EMailMessage.isValidEmailAddress(userEmail);//           TeamCCHelper.service.emailMembers(null);                 if(ok){                    mail.send(true);                    System.out.println("Email Queue got started.");                   }

 

 

Following is the output which I got

 

Connected to PDMLink!
User present in Windchill and his email id is--vigneshvino@hotmail.com
EMailMessage message submission failed
EMailMessage Can't find resource for bundle ext.gt.test.MyResources, key This isfor test
EMailMessage subject: For Windchill test
EMailMessage not submitted to: vigneshvino@hotmail.com
Email Queue got started.

 

I'm using this http://myjavadoc.net/view/viewzip.php/7994267cff17717f230350bf9dba9d7f-com.infoengine.util__-javadoc.local.zip*/api/wt/mail/EMailMessage.html#addPart(java.lang.String, java.lang.String, java.lang.Object[], java.lang.String) method from EMailMessage class to add content in text content in my mail.

Also I have placed my ResourceBundle class in package which I mentioned in code.In the output am getting the statement that I have given inside the

ResourceBundle class.

 

Can anybody tell me why this "EMailMessage Can't find resource for bundle ext.gt.test.MyResources, key This is

for test" is giving like this though I have ResourceBundle class in place?

 

Or Is there any other way to add text content to email using API?

 

Thanks,


Viewing all articles
Browse latest Browse all 6049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>