ofbiz邮件的机制
1.ofbiz中email发送的service主要定义在framework/common/servicedef/services_email.xml文件中.
2.主要用到的有
<!-- Email Related Services -->
<service name="sendMailInterface" engine="interface" location="" invoke="">
<description>Interface service for mail services. contentType defaults to "text/html", sendType defaults to
"mail.smtp.host". sendVia must be specified if sendType is different. Configured in general.properties</description>
<attribute name="sendTo" type="String" mode="IN" optional="true"/>
<attribute name="sendCc" type="String" mode="IN" optional="true"/>
<attribute name="sendBcc" type="String" mode="IN" optional="true"/>
<attribute name="sendFrom" type="String" mode="IN" optional="true"/>
<attribute name="authUser" type="String" mode="IN" optional="true"/>
<attribute name="authPass" type="String" mode="IN" optional="true"/>
<attribute name="port" type="String" mode="IN" optional="true"/>
<attribute name="sendVia" type="String" mode="IN" optional="true"/>
<attribute name="sendType" type="String" mode="IN" optional="true"/>
<attribute name="socketFactoryClass" type="String" mode="IN" optional="true"/>
<attribute name="socketFactoryPort" type="String" mode="IN" optional="true"/>
<attribute name="socketFactoryFallback" type="String" mode="IN" optional="true"/>
<attribute name="sendFailureNotification" mode="IN" type="Boolean" optional="true"/>
<attribute name="sendPartial" mode="IN" type="Boolean" optional="true"/>
<attribute name="startTLSEnabled" mode="IN" type="Boolean" optional="true"/>
<attribute name="subject" type="String" mode="INOUT" optional="true" allow-html="safe"/>
<attribute name="contentType" type="String" mode="INOUT" optional="true"/>
<attribute name="partyId" type="String" mode="INOUT" optional="true"/>
<attribute name="messageId" type="String" mode="INOUT" optional="true"/>
<attribute name="emailType" type="String" mode="INOUT" optional="true"/>
<attribute name="orderId" type="String" mode="INOUT" optional="true"/>
<attribute name="custRequestId" type="String" mode="INOUT" optional="true"/>
<attribute name="messageWrapper" type="org.ofbiz.service.mail.MimeMessageWrapper" mode="OUT" optional="true"/><!-- mail can be disabled in general.properties so no output -->
<!-- used for parsing and ECAs -->
<attribute name="communicationEventId" type="String" mode="INOUT" optional="true"/>
</service>
<service name="sendMailOnePartInterface" engine="interface" location="" invoke="">
<description>Interface service for sendMail* services.</description>
<implements service="sendMailInterface"/>
<attribute name="body" type="String" mode="INOUT" optional="false" allow-html="safe"/>
<override name="contentType" mode="INOUT"/>
<override name="subject" mode="INOUT" optional="false"/>
<override name="emailType" type="String" mode="INOUT" optional="true"/>
<override name="sendTo" optional="false"/><!-- service will give an NPE when not provided -->
</service>
<service name="sendMail" engine="java"
location="org.ofbiz.common.email.EmailServices" invoke="sendMail">
<description>Send E-Mail Service. partyId and communicationEventId aren't used by sendMail
but are passed down to storeEmailAsCommunication during the SECA chain. See sendMailInterface for more comments.</description>
<implements service="sendMailOnePartInterface"/>
</service>
3.邮件服务器相关的配置在framework/common/config/general.properties目录下(也可以修改系统自带的SystemProperty表中的参数).
配置如下:
mail.notifications.enabled=Y
mail.smtp.relay.host=smtp.ym.163.com
mail.smtp.auth.user=xxxxxx@163.com
mail.smtp.auth.password=xxxxxxxx
mail.smtp.socketFactory.port=465
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
4.调用相关service即可
<simple-method method-name="createTestData" short-description="create a Person"> <make-value entity-name="TestTable" value-field="newEntity"/> <sequenced-id sequence-name="TestTable" field="newEntity.testId"/> <set field="newEntity.username" value="Y"/> <set field="newEntity.password" value="N"/> <set field="sendMail.sendFrom" value="wangrui@zkxltech.com"/> <set field="sendMail.sendTo" value="18707148825@163.com"/> <set field="sendMail.subject" value="test"/> <set field="sendMail.body" value="wangrui test!!!!"/> <call-service service-name="sendMail" in-map-name="sendMail"> </call-service> <create-value value-field="newEntity"/> </simple-method>
浙公网安备 33010602011771号