Sending Mail AND Java

I am using the below methode to send e-mails to users from events in an application. Works very will except when I try to send an e-mail to someone outside of the company. Can someone tell me what I am doing wrong???

public String sendMailANon(String strPrincipal, String strTo, String strCC, String strBCC, String strSubject, String strUNID, String strStatus, String strCustomerName)

	{

		try {

	            Session curSession = getSession();

             AgentContext agentContext = curSession.getAgentContext();

             Database curDb = agentContext.getCurrentDatabase();



             Document contextDoc = agentContext.getDocumentContext();                 

                              

             String mailSendTo = strTo;

             String mailSubject = strSubject;        

                              

             String mailBody1 = "A " + strStatus + " form has been submitted for " + strCustomerName + "";

             String mailBody2 = "" + "To open the " + strStatus + " form click on the below URL Link";

             String mailBody3 = "" + "/enhancedservices/esf.nsf/UNID2/" + strUNID + "?EditDocument";

             

             String mailBody = mailBody1 + " " + mailBody2 + " " + mailBody3;

              

             Document memo = curDb.createDocument();

                                 memo.appendItemValue("Form", "Memo");

                                  

                                 memo.appendItemValue("Principal", strPrincipal);

                                memo.appendItemValue("From", strPrincipal);

                                memo.appendItemValue("AltFrom", strPrincipal);

                                memo.appendItemValue("SendFrom", strPrincipal);

                                memo.appendItemValue("INetFrom", strPrincipal);

                                memo.appendItemValue("tmpDisplaySentBy", strPrincipal);

                                memo.appendItemValue("tmpDisplayFrom_Preview", strPrincipal);

                                memo.appendItemValue("DisplaySent", strPrincipal);

                                

                                 Item textItemTo = memo.replaceItemValue("SendTo", strTo);

                                 Item textItemCC = memo.replaceItemValue("CopyTo", strCC);

                                 Item textItemBCC = memo.replaceItemValue("BlindCopyTo", strBCC);

                                 

                                 memo.appendItemValue("Subject", strSubject);

                                 RichTextItem rti = memo.createRichTextItem("Body");

                                 RichTextStyle header = curSession.createRichTextStyle();

                                                           header.setBold(RichTextStyle.YES);

                                                           header.setColor(RichTextStyle.COLOR_DARK_BLUE);

                                                           header.setEffects(RichTextStyle.EFFECTS_SHADOW);

                                                           header.setFont(RichTextStyle.FONT_ROMAN);

                                                           header.setFontSize(14);

                                 RichTextStyle byline = curSession.createRichTextStyle();

                                                           byline.setBold(RichTextStyle.YES);

                                                           byline.setColor(RichTextStyle.COLOR_DARK_BLUE);

                                                           byline.setEffects(RichTextStyle.EFFECTS_NONE);

                                                           byline.setItalic(RichTextStyle.NO);

                                                           byline.setFontSize(10);

                                 RichTextStyle normal = curSession.createRichTextStyle();

                                                           normal.setItalic(RichTextStyle.NO);

                                                           normal.setBold(RichTextStyle.NO);

                                                           normal.setColor(RichTextStyle.COLOR_BLACK);

                                                           normal.setUnderline(RichTextStyle.NO);

                                                           normal.setStrikeThrough(RichTextStyle.NO);

                                                           normal.setFontSize(10);

                                 RichTextStyle underline = curSession.createRichTextStyle();

                                                           underline.setUnderline(RichTextStyle.YES);

                                 RichTextStyle strike = curSession.createRichTextStyle();

                                                           strike.setStrikeThrough(RichTextStyle.YES);

  // Generate Body item

                                  //doc.renderToRTItem(rti);

                                  rti.appendStyle(byline);

                                  rti.appendText(mailBody1);    

                                  rti.addNewLine(2);

                                  rti.appendStyle(normal);

                                  rti.appendText(mailBody2);    

                                  rti.addNewLine(2);

                                  rti.appendStyle(byline);

                                  rti.appendText(mailBody3); 

                                  rti.appendStyle(normal);   

                                  

                                  //Vector v = new Vector();

                                  //v.addElement(strTo);

                                  //v.addElement(strCC);

                                  //v.addElement(strBCC);

                                  

                                  memo.setEncryptOnSend(true);

                                  memo.setSaveMessageOnSend(true);

                                  memo.setSignOnSend(true);

                                  memo.sign();

                                  //memo.send(true, v);

                                  memo.send(false);

                                  memo.recycle();

     return "OK";              

    } 

    catch(Exception e) {

             //e.printStackTrace();       

             return e.getMessage();           

             }

	}

Subject: Sending Mail AND Java

I had a similar problem (a long time ago). From what I recall the emails were being stopped by the SMTP gateway. It had to do with the value in the ‘From’ field. Check with your SMTP gateway admin and make sure that you can send outbound emails with the name in your ‘From’ parameter.

Subject: RE: Sending Mail AND Java

I know I can as this works in Lotus Script.If I remove that value,I still get locked up

Subject: RE: Sending Mail AND Java

I didn’t think you could override the From field in LS (it always sends it from the agent signer).

Are you getting any errors or delivery failures?

What does the log.nsf say? Does the Misc. Events view show “…Transferred 1 messages to xxxxx” at the time the agent ran?

If so, you should be able to go to the Mail Routing events view and get the message id to see how far it’s going.

Subject: RE: Sending Mail AND Java

I have been doing this in Lotus Script for years and it has worked great. now I am trying to recreate it in Java. I am not able to locate any error messages in the Log. I did not think that Java wrote errors to the log.When I run the java agent my notes client locks up. It locks up only when I try to send to outside of my Notes domain, like a hotmail.com account

Subject: RE: Sending Mail AND Java

If it’s running on the server the “e.printStackTrace()” will print to the Notes log (assuming it’s not commented out.)

As a matter of fact you could add some strategically placed System.out.println(“some debug text”); to help you figure out where it’s dying.

My suggestion about looking at the Notes log was to see if it had dropped the mail into the mail router (and maybe it was dying after that).

If you’re running it on your client you should start the Java Debug Console (File - Tools - Show Java Debug).

Another suggestion would be to write a bare-bones java agent that sends a test email and see what it does.

Hope this helps - I’m gone for the day…

Subject: RE: Sending Mail AND Java

I have pop up messages placed throughout the code so that I know where the app has cleared and where it has failed. It really does not tell me anything as far as errors are, it just locks up

Subject: RE: Sending Mail AND Java

Do you get the same results if you do a no-frills agent like so? (which works for me.)

Also, are you testing this locally or as a scheduled agent on the server?


import lotus.domino.*;

public class JavaAgent extends AgentBase {

Database db;

public void NotesMain() {



	try {

		

		Session session = getSession();

		AgentContext agentContext = session.getAgentContext();

		db = agentContext.getCurrentDatabase();

		sendNotice();



	} catch(Exception e) {

		e.printStackTrace();

	}

}



public void sendNotice() {



	Document email;

	RichTextItem rtItem;

	try {

		email = db.createDocument();

		email.appendItemValue("Form", "memo");

		email.appendItemValue("SendTo", "<insert email address>");

		email.appendItemValue("Subject", "basic java email test.");

		rtItem = email.createRichTextItem("Body");

		rtItem.appendText("This is a test, this is only a test.....");

		email.send();

	

		} 

	catch (NotesException nex){

		System.out.println("Send Notice");

		nex.printStackTrace();

		}

}

}


Subject: RE: Sending Mail AND Java

this worked but I have to be able to alter who the e-mail came from

Subject: RE: Sending Mail AND Java

I really don’t think Notes will allow you to do this (although it would not cause your system to lockup - again, I recommend putting some System.out.println() in different spots and enabling the Java Debug Console to try to figure out where it’s dying).

In any case, when I modify the ‘From’ on the code I posted Notes just send it as if it was from me (as I expected since I signed the agent.)

If your requirement is that the ‘From’ field change depending on certain conditions I would suggest going a non-notes way. Maybe write a servlet that uses the JavaMail API. It will allow you to insert what ever you want in the From field and drop your email into your SMTP gateway.

If the ‘From’ can remain static but you just don’t want the emails showing they came from you, I would have the Notes Administrator create an id (call it “ Notification”) and stamp your agent with it.

Sorry I could not be more help…

Subject: RE: Sending Mail AND Java

no worries, thanks anyway.to clear up what you tried to do.

The from field is not the only field that you have to change, there is a list of fields to cover all options.

memo.appendItemValue(“Principal”, strPrincipal);

memo.appendItemValue(“From”, strPrincipal);

memo.appendItemValue(“AltFrom”, strPrincipal);

memo.appendItemValue(“SendFrom”, strPrincipal);

memo.appendItemValue(“INetFrom”, strPrincipal);

memo.appendItemValue(“tmpDisplaySentBy”, strPrincipal);

memo.appendItemValue(“tmpDisplayFrom_Preview”, strPrincipal);

memo.appendItemValue(“DisplaySent”, strPrincipal);

if you miss one of them, you open yourself up to someone finding out who really sent the e-mail

As I said before, I have made this work in Lotus Script and now in Java. I suspect my problem is in how the SMTP is configured, but I would have to take that up with my Admin.

Subject: RE: Sending Mail AND Java

Why not just use the ‘Run on behalf of’ option on the Agent Properties? This would send the email from whomever you listed.

Using the fields you listed above is a hack, just as is the old method of putting documents directly into mail.box. I would expect this loophole to eventually be closed off in later releases as it is a potential security violation.

Subject: RE: Sending Mail AND Java

yes you would do that and yes my code is a hack, but it works and it allows you to change who the sender is programmicly