Invoke Code with SMTP mail without username/password email variable

Dear Experts,

I am trying to send an email, using the invoke code activity, and it is working fine.
But i need to define a variable for the target email ,as seen below line:

mailMsg.To.Add(xxx@gmail.com) to be like mailMsg.To.Add(+“Email”+), where email=xxx@gmail.com

But if i write anything apart from the email, it throws a error for exception in code.

So, any one has experience on how to call the target email, as a input variable from a end user?

Full invoke code sample:
Dim smtpClient As New System.Net.Mail.SmtpClient(in_MailServer)
Dim mailMsg As New System.Net.Mail.MailMessage
Dim sender As New System.Net.Mail.MailAddress(in_Sender)
mailMsg.To.Add(in_MailTo)
mailmsg.Body = in_MailMsgBody
mailMsg.Subject = in_Subject
mailMsg.From = sender
mailMsg.IsBodyHtml = True
smtpClient.Port = Integer.Parse(in_MailPort)
smtpClient.Send(mailMsg)

Hi @saadahsan

I am not answering your question fully, but to easy your automation you could use the “Send SMTP Mail Message” activity, which contains the relevant input for the SMTP mail:

Best Regards,
Martin

Why not use an InputDialog before you Invoke your emai.xaml and pass the email as Well?

Can you please elaborate what exactly you want to achieve ?

I can use, input dialog to take the email address as input, as an example the email is XXX@gmail.com and assign it to a variable called “email”. Now i want to call this variable in the invoke code sample attached above? how to do that?

I can use, input dialog to take the email address as input, as an example the email is XXX@gmail.com and assign it to a variable called “email”. Now i want to call this variable in the invoke code sample attached above? how to do that?

Thanks Martin, but i am using invoke code, as i do not have a username password, so invoke code is an alternative, and it works fine in my case. But i need to call a variable, which should be target email in the code, which i am trying to figure out how?

Hi @saadahsan

Just to clarify the use of the SMTP Activity. The SMTP “Username/Password” is optional if your SMTP server does not require it.
I respect if you want to use the Invoke Code, but the Activity is quite effective.

Best Regards,
Martin

you pass it as argument like the others “in_…”

1 Like

how to get mail in outlook web or gmail using invoke code?

Hi

i am try to implement the similar functionality.
i am new to uipath. i am trying to send email using invoke code activity but i working for me.
Can you please find.

Thank you