In this post, I will demonstrate how to send an e-mail with the help of Gmail’s SMTP
server. Instead of going for the OdiSendMail tool, I will be using the Jython technology
in order to implement the same functionality.
Create a new Procedure under any of your existing Projects in the Designer tab. Name
the procedure SendEmail. Switch to Tasks and add a new entry.
Now, under Command on Target, you need to write the Jython code. Please make
sure you have selected Technology as Jython.
Replace your email address. I have used abc@gmail.com is sender and
Toemail@gmail.com as receiver email.
import smtplib
import string
BODY = string.join((
“From: %s” % ‘abc@gmail.com’,
“To: %s” % ‘Toemail@gmail.com’,
“Subject: %s” % ‘Test Mail’,
“”,’This is a test email from ODI’
), “\r\n”)
sender = smtplib.SMTP(‘smtp.gmail.com’,587)
sender.set_debuglevel(1)
sender.ehlo()
sender.starttls()
sender.ehlo()
sender.login(‘abc@gmail.com’, ‘GmailPassword’)
sender.sendmail(‘abc@gmail.com’,[‘Toemail@gmail.com’],BODY)
sender.close()
Now after this I tried to run the procedure but it failed for me.
ODI-1590: The execution of the script failed. ODI-1590: The execution of the script
failed. Caused By: org.apache.bsf.BSFException: exception from Jython:Traceback
(most recent call last): File “<string>”, line 15, in <module> File
“C:\ODI12c\odi\sdk\lib\Lib\smtplib.py”, line 591, in login raise
SMTPAuthenticationError(code, resp)smtplib.SMTPAuthenticationError: (534, ‘5.7.14
<https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=\n5.7.14 \n5.7.14
wf2rMTkfdysmOMsG3ojvUb4D-CS4dLjteh2dtDNVQmDgpzEQZPWY-BbN2ouh-
4bvcONN4-\n5.7.14 Kk0H3K-5qGwiEAie_oZxDiPJCPTbA> Please log in via your web
browser and\n5.7.14 then try again.\n5.7.14 Learn more
at\n5.7.14 https://support.google.com/mail/answer/78754l6sm30263827pfc.112 –
gsmtp’)
at org.apache.bsf.engines.jython.JythonEngine.exec(JythonEngine.java:146)
at com.sunopsis.dwg.codeinterpretor.SnpScriptingInterpretor.execInBSFEngine(SnpScr
iptingInterpretor.java:353)
at com.sunopsis.dwg.codeinterpretor.SnpScriptingInterpretor.exec(SnpScriptingInterpre
tor.java:216)
at oracle.odi.runtime.agent.execution.interpreter.SessionTaskScriptingInterpretor.scripti
ng(SessionTaskScriptingInterpretor.java:171)
at oracle.odi.runtime.agent.execution.SessionTask.scripting(SessionTask.java:105)
at oracle.odi.runtime.agent.execution.cmd.ScriptingExecutor.execute(ScriptingExecutor.
java:49)
at oracle.odi.runtime.agent.execution.cmd.ScriptingExecutor.execute(ScriptingExecutor.
java:21)
at oracle.odi.runtime.agent.execution.TaskExecutionHandler.handleTask(TaskExecutio
nHandler.java:52)
at oracle.odi.runtime.agent.execution.SessionTask.processTask(SessionTask.java:206)
at oracle.odi.runtime.agent.execution.SessionTask.doExecuteTask(SessionTask.java:1
17)
at oracle.odi.runtime.agent.execution.AbstractSessionTask.execute(AbstractSessionTa
sk.java:886)
at oracle.odi.runtime.agent.execution.SessionExecutor$SerialTrain.runTasks(SessionE
xecutor.java:2227)
at oracle.odi.runtime.agent.execution.SessionExecutor.executeSession(SessionExecut
or.java:607)
at oracle.odi.runtime.agent.processor.TaskExecutorAgentRequestProcessor$1.doActio
n(TaskExecutorAgentRequestProcessor.java:718)
at oracle.odi.runtime.agent.processor.TaskExecutorAgentRequestProcessor$1.doActio
n(TaskExecutorAgentRequestProcessor.java:611)
at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTempl
ate.java:203)
at oracle.odi.runtime.agent.processor.TaskExecutorAgentRequestProcessor.doProcess
StartAgentTask(TaskExecutorAgentRequestProcessor.java:800)
at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$1400(St
artSessRequestProcessor.java:74)
at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$StartSessTask.
doExecute(StartSessRequestProcessor.java:702)
at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:180)
at oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$2.run(DefaultAgentTask
Executor.java:108) at java.lang.Thread.run(Thread.java:745)Caused by: Traceback
(most recent call last): File “<string>”, line 15, in <module> File
“C:\ODI12c\odi\sdk\lib\Lib\smtplib.py”, line 591, in login raise
SMTPAuthenticationError(code, resp)smtplib.SMTPAuthenticationError: (534, ‘5.7.14
<https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvZ\n5.7.14
jIoPKsYbnMcRU-
zduQz03BVfdBGY9VHoLlOZU8bG9_ojfaR9CbOTUH1lJ08SJfDCmFaRX6\n5.7.14
LhJC1Yqv0w4LsIwLd2uzPr6m0rEH67_hlyL4O2OP-
kLwzYcRedJnSsJcQWuOpCyO52PKvq\n5.7.14 wf2rMTkfdysmOMsG3ojvUb4D-
CS4dLjteh2dtDNVQmDgpzEQZPWY-BbN2ouh-4bvcONN4-\n5.7.14 Kk0H3K-
5qGwiEAie_oZxDiPJCPTbA> Please log in via your web browser and\n5.7.14 then try
again.\n5.7.14 Learn more
at\n5.7.14 https://support.google.com/mail/answer/78754l6sm30263827pfc.112 –
gsmtp’)
at org.python.core.PyException.doRaise(PyException.java:219)
at org.python.core.Py.makeException(Py.java:1166)
at org.python.core.Py.makeException(Py.java:1170)
at org.python.core.Py.makeException(Py.java:1174) at
smtplib$py.login$42(C:\ODI12c\odi\sdk\lib\Lib\smtplib.py:592) at
smtplib$py.call_function(C:\ODI12c\odi\sdk\lib\Lib\smtplib.py)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyBaseCode.call(PyBaseCode.java:297)
at org.python.core.PyBaseCode.call(PyBaseCode.java:191)
at org.python.core.PyFunction.__call__(PyFunction.java:385)
at org.python.core.PyMethod.__call__(PyMethod.java:215)
at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:221)
at org.python.core.PyMethod.__call__(PyMethod.java:206)
at org.python.core.PyObject.__call__(PyObject.java:414)
at org.python.core.PyObject.__call__(PyObject.java:418) at
org.python.pycode._pyx18.f$0(<string>:17) at
org.python.pycode._pyx18.call_function(<string>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1204) at org.python.core.Py.exec(Py.java:1248)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:172)
at org.apache.bsf.engines.jython.JythonEngine.exec(JythonEngine.java:144)
This is happening because our gmail server is not allowing to send email via un-trusted
Tools. To allow Gmail to do this, go to the below link. Login with your gmail credentials.
https://myaccount.google.com/lesssecureapps?pli=1
Enjoy!