Sandor Rozsa wrote:

Hi,

just a quick one:

what exactly do we have to set up to get the mail-form samples working?
Under form properties there is a "mail-server" field? How should the mail
server be specified here? Can I use a remote smtp-server or do I have to use
a mailserver on the same machine? If smtp is possible: where do I
authenticate myself? Do I have to publish the form to test it, or will it
function - once configured properly - also on the authoring side?

Any other places where configuration is necessary?

For the moment I'm getting only a 404 - The requested resource
(/features/mailform.html) is not available.

TIA

Sandor


----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/magnolia/developer.html
----------------------------------------------------------------

Hi Sandor,

I had the same problem as you.

The reason is that the implementation of the info.magnolia.cms.util.MailHandler.java does not send messages the way your mailserver is configured (authentification etc. just what the exception says).

I solved this problem by a new class MailHandler2.java. This class is identical with the original one, except for the constructor and the sendMail() method. The snippets are given below.

Cheers,
Christoph

public MailHandler2(int toListLength, int ccListLength) throws Exception {
      toList = new InternetAddress[toListLength];
      ccList = new InternetAddress[ccListLength];
Properties props = System.getProperties();
      props.setProperty("mail.transport.protocol", "smtp");
        props.setProperty("mail.host", "auth.smtp.yourServer.de");
        props.setProperty("mail.user", "yourUsername");
        props.setProperty("mail.password", "yourPasswd");
        props.setProperty("mail.smtp.auth","true");
session = Session.getDefaultInstance(props, null);
        transport = session.getTransport();
transport.connect("auth.smtp.yourServer.de", "yourUsername", "YourPassword");
  }

  public void sendMail() throws MessagingException {
      try {
          MimeMessage message = new MimeMessage(session);
          message.setFrom(new InternetAddress(this.getFrom()));
message.setRecipients(Message.RecipientType.TO, this.getToList()); message.setRecipients(Message.RecipientType.CC, this.getCcList());
          message.setSubject(subject);

          message.setContent(body, "text/plain");
          message.setHeader("Content-Type", "text/plain; charset=UTF-8");

          transport.sendMessage(message, getToList());
log.info("Mail has been sent to: [" + addressesToString(this.getToList()) + "]");
      }
      catch (MessagingException e) {
          log.error("Email to: ["
              + addressesToString(this.getToList())
              + "] was not sent because of the following error: "
              + e.getMessage(), e);
          throw e;
      }
      catch (RuntimeException e) {
          // this is here in order to catch UnsupportedOperationException
          // by alternative javamail libraries
          log.error("Email to: ["
              + addressesToString(this.getToList())
              + "] was not sent because of the following error: "
              + e.getMessage(), e);
          throw e;
      }

----------------------------------------------------------------
for list details see
http://www.magnolia.info/en/magnolia/developer.html
----------------------------------------------------------------

Reply via email to