viggnah
viggnah

Reputation: 1879

How to receive emails using WSO2 MI?

This is only on a localhost setup. Followed this documentation and set the following in my proxy (replacing the email address, username, and password with my personal email):

<parameter name="transport.mail.Address">[email protected]</parameter>
<parameter name="transport.mail.Protocol">pop3</parameter>
<parameter name="transport.PollInterval">1</parameter>
<parameter name="mail.pop3.host">pop.gmail.com</parameter>
<parameter name="mail.pop3.port">995</parameter>
<parameter name="mail.pop3.user">synapse.demo.1</parameter>
<parameter name="mail.pop3.password">mailpassword1</parameter>
<parameter name="mail.pop3.socketFactory.class">javax.net.ssl.SSLSocketFactory</parameter>
<parameter name="mail.pop3.socketFactory.fallback">false</parameter>
<parameter name="mail.pop3.socketFactory.port">995</parameter>
<parameter name="transport.mail.ContentType">text/plain</parameter>

After starting the proxy service on my localhost, when I send an email to my personal email nothing is picked up. Not sure if I have to do anything else?

Copied and tried the proxy service given in this older answer but still doesn't work.

Upvotes: 0

Views: 104

Answers (1)

ycr
ycr

Reputation: 14594

Few pointers are below.

First, you need to enable mailto transport receiver in axis2.xml to receive Emails. See the below.

    <transportReceiver name="mailto" class="org.apache.axis2.transport.mail.MailTransportListener">
        <!-- configure any optional POP3/IMAP properties
        check com.sun.mail.pop3 and com.sun.mail.imap package documentation for more details-->
    </transportReceiver>

Also, with Gmail POP3 servers you can no longer use your email password for authentication. This is because on the 30th of May 2022 Less Secure App option was removed by Google. So instead of using your password, you need to generate an App password. You can refer this to generate an App password. Make sure your account has two-factor authentication enabled, otherwise this option will be disabled. Once the above is done following proxy will work.

<?xml version="1.0" encoding="UTF-8"?><proxy xmlns="http://ws.apache.org/ns/synapse" name="Email" startOnLoad="true">
    <description/>
    <target>
        <inSequence>
            <property name="senderAddress" expression="get-property('transport', 'From')" scope="default" type="STRING"/>
            <log level="full">
                <property name="Date" expression="$trp:Date"/>
                <property name="Subject" expression="$trp:Subject"/>
                <property name="Content-Type" expression="$trp:Content-Type"/>
                <property name="From" expression="$trp:From"/>
            </log>
            <drop/>
        </inSequence>
        <outSequence>
            <send/>
        </outSequence>
    </target>
    <parameter name="mail.pop3.socketFactory.class">javax.net.ssl.SSLSocketFactory</parameter>
    <parameter name="transport.PollInterval">5</parameter>
    <parameter name="mail.pop3.host">pop.gmail.com</parameter>
    <parameter name="mail.pop3.user">user1</parameter>
    <parameter name="transport.mail.Protocol">pop3</parameter>
    <parameter name="mail.pop3.socketFactory.port">995</parameter>
    <parameter name="transport.mail.Address">[email protected]</parameter>
    <parameter name="mail.pop3.password">APP_PASSWORD</parameter>
    <parameter name="mail.pop3.port">995</parameter>
    <parameter name="mail.pop3.socketFactory.fallback">false</parameter>
    <parameter name="transport.mail.ContentType">text/plain</parameter>
</proxy>

If you still see issues you can enable debug logs and see what's happening. Add the following line to log4j.properties

log4j.logger.org.apache.axis2.transport.mail.MailTransportListener=DEBUG

Upvotes: 1

Related Questions