• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: SMTPHost Setting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SMTPHost Setting


  • Subject: Re: SMTPHost Setting
  • From: Sam Barnum <email@hidden>
  • Date: Mon, 11 Apr 2005 07:07:22 -0700

I think the problem is, you need to set the properties _before_ you pass them to the Session constructor. The Session makes a defensive copy of the properties, so changing the properties after Session initialization doesn't affect the session. Likewise, session.getProperties() returns a copy of the properties, not the in-use properties object.

--
Sam Barnum
360 Works
http://www.360works.com
415.929.7318


On Apr 10, 2005, at 7:46 AM, Drew Thoeni wrote:

Sam,

I think I get this with one gap, your variable theHost: isn't that the key in the Properties array for the keyValue smtpHost?

What is the literal in theHost or how is theHost later referenced by new MimeMessage(defaultMailSession) to get the SMTP host?

My code is below for reference...

public static void sendAMessage(String from, String to, String subject, String body) {
javax.mail.Session defaultMailSession = javax.mail.Session.getDefaultInstance(new Properties());
Properties props = defaultMailSession.getProperties();
props.setProperty("smtp.myDomain.com","smtpHost"); // replaced domain name for posting to listserv

try {
Message aMessage = new MimeMessage(defaultMailSession);
aMessage.setSentDate(new Date());
aMessage.setFrom(new InternetAddress(from));
aMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
aMessage.setSubject(subject);
aMessage.setText(body);
Transport.send(aMessage);
}
catch (SendFailedException sfex) { Log.log(null,"SendFailedException: " + sfex); }
catch (MessagingException mex) { Log.log(null,"SendFailedException: " + mex); }
return;
}




On Apr 10, 2005, at 10:13 AM, Sam Barnum wrote:

You'll want to set the SMTP server in the javax.mail.Session properties.

javax.mail.Session defaultMailSession = javax.mail.Session.getDefaultInstance(new Properties(), null);
if (theHost != null) {
// Fixed a bug where the SMTP host is cached in the javax.mail.Session the first time it is instantiated -sb
defaultMailSession.getProperties().setProperty("mail.smtp.host", theHost);
}
return defaultMailSession;


This example doesn't do so, but you can also use the System.properties, and pass that into the Session. It's a little more complicated if you want to use different smtp servers, since I think the javax.mail.Session caches the value (not sure though)

--
Sam Barnum
360 Works
http://www.360works.com
415.929.7318


On Apr 9, 2005, at 4:59 PM, John Bruce wrote:

If you want to save yourself some effort ERJavaMail from Project
Wonder is an implementation of JavaMail for WebObjects. AFAIK it
doesn't required the rest of PW.

Cheers,

John



On Apr 10, 2005 8:26 AM, Drew Thoeni <email@hidden> wrote:
I'm trying t implement javaMail and am getting pretty close. However, I
am getting an exception:


SendFailedException: javax.mail.MessagingException: Could not connect
to SMTP host: localhost, port: 25;
nested exception is: java.net.ConnectException: Connection refused


The connection is being refused because I don't have a mail server set
up on my development machine. I'm trying setting the SMTP host using
one (or both) of the commands below, but it seems neither is recognized
by javaMail and it apparently defaults to localHost.


What is the difference between these two command and why doesn't
javaMail recognize either. WOMailDelivery boes recognizes
setSMTPHost(), but I'm trying to use BCC which WOMailDelivery does not
support.


Application.setSMTPHost("smtp.domain.com")

OR

Properties props = new Properties();
props.put("smtp.domain.com", "SMTP Host Name");

Regards,

Drew


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden



_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >SMTPHost Setting (From: Drew Thoeni <email@hidden>)
 >Re: SMTPHost Setting (From: John Bruce <email@hidden>)
 >Re: SMTPHost Setting (From: Sam Barnum <email@hidden>)
 >Re: SMTPHost Setting (From: Drew Thoeni <email@hidden>)

  • Prev by Date: [WOBuilder] Add value sets to bindings?
  • Next by Date: Re: OpenBase vs MySQL
  • Previous by thread: Re: SMTPHost Setting
  • Next by thread: Re: SMTPHost Setting
  • Index(es):
    • Date
    • Thread