Hello,

here is a problem with my e-mail base-configuration.

I configured email according to the setup guide:

https://cwiki.apache.org/confluence/display/OFBIZ/Apache+OFBiz+Technical+Production+Setup+Guide#ApacheOFBizTechnicalProductionSetupGuide-EmailServerSettings


Unfortunately no email seems to be sent from server
(the send email button in partymgr works fine now (thanks to Jacques!),
but no email reaches client). No error message, no error in log.

Also I tried to register in the ecommerce system and send
an "Forgot Your Password" email, but none of the emails were sent.

To get more info about the problem, I wrote a groovy script and copied
parts of the sendEmail-code from EmailServices.java.
The script below surprisingly works fine and sends emails!

So I don't understand, why OFBiz itself does not send mails.
Is there any further configuration necessary?



The script (which sends mails):

import javax.mail.Session;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.stream.StreamSource;

import org.apache.fop.apps.Fop;
import org.apache.fop.apps.MimeConstants;
import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.GeneralException;
import org.apache.ofbiz.base.util.HttpClient;
import org.apache.ofbiz.base.util.HttpClientException;
import org.apache.ofbiz.base.util.UtilGenerics;
import org.apache.ofbiz.base.util.UtilMisc;
import org.apache.ofbiz.base.util.UtilProperties;
import org.apache.ofbiz.base.util.UtilValidate;
import org.apache.ofbiz.base.util.collections.MapStack;
import org.apache.ofbiz.base.util.string.FlexibleStringExpander;
import org.apache.ofbiz.entity.Delegator;
import org.apache.ofbiz.entity.GenericValue;
import org.apache.ofbiz.entity.util.EntityUtilProperties;
import org.apache.ofbiz.service.DispatchContext;
import org.apache.ofbiz.service.GenericServiceException;
import org.apache.ofbiz.service.LocalDispatcher;
import org.apache.ofbiz.service.ServiceUtil;
import org.apache.ofbiz.service.mail.MimeMessageWrapper;
import org.apache.ofbiz.webapp.view.ApacheFopWorker;
import org.apache.ofbiz.widget.renderer.macro.MacroScreenRenderer;
import org.apache.ofbiz.widget.renderer.ScreenRenderer;
import org.apache.ofbiz.widget.renderer.ScreenStringRenderer;
import org.xml.sax.SAXException;

def testMail() {
        sendType = "mail.smtp.host"
        sendVia = "smtp.myhost.com"
        Properties props = System.getProperties()
    props.put(sendType, sendVia)
    Session session
    session = Session.getInstance(props);
    MimeMessage mail
    mail = new MimeMessage(session);
        Transport trans = null
        sendFrom = "obfiz.example.com"
        sendTo = "m...@myserver.de"
        subject = "testMail from OFBiz"
        mp = new MimeMultipart();
        
        MimeBodyPart mbp = new MimeBodyPart();
        mbp.setText("Content: a test mail from OFBiz system")
        
        mp.addBodyPart(mbp);
        mail.setContent(mp);
        
        mail.setFrom(new InternetAddress(sendFrom));
        mail.setSubject(subject, "UTF-8");
        mail.setHeader("X-Mailer", "Apache OFBiz, The Open For Business 
Project");
        mail.setSentDate(new Date());
        mail.addRecipients(Message.RecipientType.TO, sendTo);
        
        trans = session.getTransport("smtp")
        authUser = UtilProperties.getPropertyValue('general.properties',
'mail.smtp.auth.user')
        authPass = UtilProperties.getPropertyValue('general.properties',
'mail.smtp.auth.password')

    trans.connect(sendVia, authUser, authPass);
        trans.sendMessage(mail, mail.getAllRecipients())
        trans.close()
        
        logWarning("successful run of testMail ")
        logWarning(" user = " + userLogin.partyId);

        return success("this test is done successful")          
}       

Reply via email to