I just cranked out some stuff using JavaMail today--hope this helps. It's a mix of
stuff from Christian Thompson's article in CFDJ on the JavaMail API and Sun's tutorial
at http://developer.java.sun.com/developer/onlineTraining/JavaMail/contents.html
// properties
objProperties = createObject("Java", "java.util.Properties");
objProperties.init();
objProperties.put("javax.mail.smtp.host", "mailserver.somewhere.com");
// session
clsSession = createObject("Java", "javax.mail.Session");
objSession = clsSession.getInstance(objProperties);
// message
objMessage = createObject("Java", "javax.mail.internet.MimeMessage");
objMessage.init(objSession);
// to and from addresses
objFromAddress = createObject("Java", "javax.mail.internet.InternetAddress");
objFromAddress.init("[EMAIL PROTECTED]");
objToAddress = createObject("Java", "javax.mail.internet.InternetAddress");
objToAddress.init("[EMAIL PROTECTED]");
// build message
clsRecipientType = createObject("Java", "javax.mail.Message$RecipientType");
objMessage.setFrom(objFromAddress);
objMessage.addRecipient(clsRecipientType.TO, objToAddress);
objMessage.setSubject("JavaMail!");
objMessage.setText("You like using JavaMail in CFMX.");
// send message
objTransport = objSession.getTransport("smtp");
objTransport.connect("mailserver.somewhere.com", "username", "password");
objTransport.sendMessage(objMessage, objMessage.getAllRecipients());
objTransport.close();
If your SMTP server doesn't require authentication, use "" for the user name and
password in the connect method. I'm not sure since I set the host in the properties
how to avoid typing it again in the connect method, but I haven't looked into it
further.
This may not be exactly what you're after but hopefully it will give you a little more
info on things.
Matt
>Sorry to bother you again, but how would I setRecipients() in cf? I have
>tried like every different way I can think of and keep getting errors.
>
>Any help appreciated.
>
>Here's the last thing I have:
>
>messageObj.setRecipients("javax.mail.Message.RecipientType.TO", to);
>
>Timothy Heald MCP/CCFD
>Information Systems Specialist
>Overseas Security Advisory Council
>U.S. Department of State
>202.663.0130
>
>Please note that this email address is being discontinued on the 30th of
>May, 2003. Its replacement address will be [EMAIL PROTECTED] and is available
>for use now.
>
>
>
>-----Original Message-----
>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>Sent: Friday, May 23, 2003 1:59 PM
>To: CF-Talk
>Subject: Re: RE: RE: Javamail API: Using a constructor that requires
>arguments
>
>
>No. javax.mail.Session instantiates a Session object, but you don't
>actually get a session until you call the getInstance (or the other ones)
>method. See, makes perfect sense :)
>
>----- Original Message -----
>From: [EMAIL PROTECTED]
>Date: Friday, May 23, 2003 11:50 am
>Subject: RE: RE: Javamail API: Using a constructor that requires arguments
>
>> ok so doesn't javax.mail doesn't inherit session. DOH.
>>
>> Thanks,
>>
>> Timothy Heald MCP/CCFD
>> Information Systems Specialist
>> Overseas Security Advisory Council
>> U.S. Department of State
>> 202.663.0130
>>
>> Please note that this email address is being discontinued on the
>> 30th of
>> May, 2003. Its replacement address will be [EMAIL PROTECTED] and is
>> availablefor use now.
>>
>>
>>
>> -----Original Message-----
>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>> Sent: Friday, May 23, 2003 1:44 PM
>> To: CF-Talk
>> Subject: Re: RE: Javamail API: Using a constructor that requires
>> arguments
>>
>>
>> Try:
>> // set up a properties object to contain our mail properties
>> propsObj = createObject("Java", "java.util.Properties");
>> propsObj.init();
>>
>> // add the smtp server
>> propsObj.put("javax.mail.smtp.host", "10.214.250.6");
>>
>> // get a default session
>> session = createObject("Java", "javax.mail.Session");
>> sessionObj = session.getDefaultInstance(propsObj);
>>
>> // create a message object
>> messageObj = createObject("Java", "javax.mail.internet.MimeMessage");
>> messageObj.init(sessionObj);
>>
>> ----- Original Message -----
>> From: [EMAIL PROTECTED]
>> Date: Friday, May 23, 2003 11:31 am
>> Subject: RE: Javamail API: Using a constructor that requires arguments
>>
>> > OK,
>> > So it's blowing up right when I try to instantiate the MimeMessage
>> > object. I have upgraded the JRE and am still at a loss. Anyone?
>> >
>> > Timothy Heald MCP/CCFD
>> > Information Systems Specialist
>> > Overseas Security Advisory Council
>> > U.S. Department of State
>> > 202.663.0130
>> >
>> > Please note that this email address is being discontinued on the
>> > 30th of
>> > May, 2003. Its replacement address will be [EMAIL PROTECTED] and
>> is
>> > availablefor use now.
>> >
>> >
>> >
>> > -----Original Message-----
>> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>> > Sent: Friday, May 23, 2003 10:08 AM
>> > To: CF-Talk
>> > Subject: Javamail API: Using a constructor that requires arguments
>> >
>> >
>> > So we're trying out the Javamail API to send a newsletter to a
>> few
>> > thousandof our closest friends. For some reason I get the
>> > following funky error
>> > when I try to create a MimeMessage object:
>> >
>> > The system has attempted to use an undefined value, which
>> usually
>> > indicatesa programming error, either in your code or some system
>> > code.
>> >
>> > Null Pointers are another name for undefined values.
>> >
>> > Here's the code:
>> >
>> > // set up a properties object to contain our mail properties
>> > propsObj = createObject("Java", "java.util.Properties");
>> > propsObj.init();
>> >
>> > // add the smtp server
>> > propsObj.put("javax.mail.smtp.host", "10.214.250.6");
>> >
>> > // get a default session
>> > sessionObj = createObject("Java", "javax.mail.Session");
>> > sessionObj.getDefaultInstance(propsObj);
>> >
>> > // create a message object
>> > messageObj = createObject("Java",
>> "javax.mail.internet.MimeMessage");> messageObj.init(sessionObj);
>> >
>> > I have been following loosely the code from this months CFDJ as
>> > well as
>> > consulting the API docs on java.sun.com, and I can't seem to get
>> > this to
>> > work. Any one have suggestions?
>> >
>> > Timothy Heald MMCP/CCFD
>> > Information Systems Specialist
>> > Overseas Security Advisory Council
>> > U.S. Department of State
>> > 202.663.0130
>> >
>> > Please note that this email address is being discontinued on the
>> > 30th of
>> > May, 2003. Its replacement address will be [EMAIL PROTECTED] and
>> is
>> > availablefor use now.
>> >
>> >
>> >
>> >
>>
>>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Your ad could be here. Monies from ads go to support these lists and provide more
resources for the community.
http://www.fusionauthority.com/ads.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4