Message not sent through POP3/SMTP

PATTANAYAK

New Member
hi, i want to send a message through POP3/SMTP action to my mail id, but it is showing below error. can you help me out to rectify this error ?
Thanks in advance.

Internal : Could not execute code stage because exception thrown by code stage: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
 

Sachin_Kharmale

Active Member
Hi I am also facing same issue . i have solved issue using following steps:

1)Enable POP and SMTP Support from your email client .

2)Take a look you have valid security certificates install in your network ,
View attachment 1559440687277.png
POP Settings
View attachment 1559440807763.png
IMAP Settings for Gmail

3) if you are using gmail then activate the settings for SMTP and POP3 also enable the access to untrusted/External application settings from your mail.

I hope it will help you.
 

Sachin_Kharmale

Active Member
hi, i want to send a message through POP3/SMTP action to my mail id, but it is showing below error. can you help me out to rectify this error ?
Thanks in advance.

Internal : Could not execute code stage because exception thrown by code stage: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
1)Enter correct user name and Password.
2) Go to security settings at the followig linkhttps://www.google.com/settings/security/lesssecureapps and enable less secure apps . So that you will be able to login from all apps
View attachment 1559441483556.png
3)enable two-factor authentication (aka two-step verification) , and then generate an application-specific password. Use that newly generated password to authenticate via SMTP.

I think may be you had missed second point enable settings less secure app support from your gmail account settings section.

Best,
Sachin
 

kiss4344

Member
1)Enter correct user name and Password.
2) Go to security settings at the followig linkhttps://www.google.com/settings/security/lesssecureapps and enable less secure apps . So that you will be able to login from all apps
View attachment 3930
3)enable two-factor authentication (aka two-step verification) , and then generate an application-specific password. Use that newly generated password to authenticate via SMTP.

I think may be you had missed second point enable settings less secure app support from your gmail account settings section.

Best,
Sachin

faced same issue, resolved with your instructions.
 

kiss4344

Member
@Sachin_Kharmale I am unable to add a screenshot in email body, using below html code, can you please guide me

I am not adding anything in attachment( mean, not adding path in collection), will this work.

<html>
<head>
</head>
<body>
<img width=100 height=100 id=""1"" src=""cid:Untitled.png"">
</body>
</html>
 

Attachments

  • Main_Page.JPG
    134.9 KB · Views: 35
  • Attachment_Collection.JPG
    109.1 KB · Views: 26

Sachin_Kharmale

Active Member
Hi Kiss ,

If you want to add image in html body then you need absolute path of the image that you want to add in html body.
Absolute Path- absolute or full path points to the same location in a file system

Suppose your image name is abc.jpeg which is stored on D:/ Drive then Your code will be

<html>
<head>
</head>
<body>
<img src="D:/abc.jpeg" height="100" width="100">
</body>
</html>


So Loop the Attachment collection and add the images path in html code and then send email

i hope it will help you.
 
Last edited:

kiss4344

Member
Do I need to add image in Collection? Bcse I am not getting image in email.

Note: In collection I have added an excel sheet as attachment and that is working fine. But, image given in email body not attaching with email. please look into attached images.
 

Attachments

  • Email_Snapshot.JPG
    85.6 KB · Views: 21
  • Email Body.JPG
    146 KB · Views: 17

kiss4344

Member
But Sachin my mail should not contain image as an attachment, it should contain image within email body. please refer below image
 

Attachments

  • Email with screenshot within body.JPG
    33.3 KB · Views: 25

Sachin_Kharmale

Active Member
So your images are come in mail ,
So you need to Download that images from mail to your local system.
Try to download mail images to the local system .
if need need any further assistance i will help you ,
 

kiss4344

Member
So your images are come in mail ,
So you need to Download that images from mail to your local system.
Try to download mail images to the local system .
if need need any further assistance i will help you ,

Sachin - My requirement is to send an email with attachment like that.
 

Sachin_Kharmale

Active Member
Hi Kiss ,

If you send an attachment in email body follow the bellow steps ,

1)Add New action in Blue Prism SMTP/POP3 VBO as Send message with embedded Image
View attachment 1560842475655.png


2)Input parameter for start will be same as Send Message add one Parameter Extra ImagePath Text Data Type
View attachment 1560843511156.png

3)Code Stage input Parameter
View attachment 1560843545067.png

4)Code Stage Code .
View attachment 1560843576337.png

Copy Bellow Code and Paste in your code Stage.

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
SmtpClient client = new SmtpClient();
try
{
client.Host = Server;
client.Port = (int)Port;
if (Username != "")
client.Credentials = new NetworkCredential(Username,Password);
client.EnableSsl = UseSSL;

using(MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(From);
mail.To.Add(To);
mail.Subject = Subject;
mail.IsBodyHtml = BodyIsHTML;
mail.Body = Body;

foreach(DataRow dr in Attachments.Rows)
{
string file = dr["Path"].ToString();
Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
ContentDisposition dis = data.ContentDisposition;
dis.CreationDate = File.GetCreationTime(file);
dis.ModificationDate = File.GetLastWriteTime(file);
dis.ReadDate = File.GetLastAccessTime(file);
mail.Attachments.Add(data);
}

string filename = ImagePath;
string htmlBody=Body;
htmlBody = htmlBody + Environment.NewLine+ "<img src=\"cid:"+Path.GetFileName(filename)+"\">" ;
mail.IsBodyHtml = true;
mail.Body = htmlBody;
AlternateView htmlview = default(AlternateView);
htmlview = AlternateView.CreateAlternateViewFromString(htmlBody, null, "text/html");
LinkedResource imageResourceEs = new LinkedResource(filename);
imageResourceEs.ContentId = Path.GetFileName(filename);
imageResourceEs.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
htmlview.LinkedResources.Add(imageResourceEs);
mail.AlternateViews.Add(htmlview);


client.Send(mail);
}
}
catch(Exception ex)
{
string msg = ex.Message;
if(ex.InnerException != null) {
msg += " - " + ex.InnerException.Message;
}
throw new Exception(msg);
}
finally
{
IDisposable disposableClient = client as IDisposable;
if (disposableClient!=null)
disposableClient.Dispose();
}


5) Publish action and Call Action from process studio
View attachment 1560843790534.png

6)After sending mail you will get mail with image in mail body .

View attachment 1560843916988.png

I hope it will help you.
 

mundhir123

New Member
Hi I am also facing same issue . i have solved issue using following steps:

1)Enable POP and SMTP Support from your email client .

2)Take a look you have valid security certificates install in your network ,
View attachment 3928
POP Settings
View attachment 3929
IMAP Settings for Gmail

3) if you are using gmail then activate the settings for SMTP and POP3 also enable the access to untrusted/External application settings from your mail.

I hope it will help you.


Hi Sachin,

I am facing exactly the same issue and followed all the steps mentioned by you. But still the problem persists and the mail was not sent through.
I am getting the error "The remote certificate is invalid according to the validation procedure".

Is there workaround required on certificates?
FYI, I have installed google certificate in trusted root and intermediate CA.
 

mundhir123

New Member
Hi Mundhir,
The problem with the certificate please install proper required certificates to work it properly.

Hi Sachin,
Could you elaborate little more on this proper certificate? I tried it on mmc certificate snap in and google certificate are showing valid. Still encountering the same error.

Thanks in advance for your time.
 

irvinborder

New Member
Log in to your Gmail account through a web browser and enable access through less secure apps . Less secure apps can make your account more vulnerable, Google will automatically turn this setting off if it's not being used. However, bypass this security setting with a configuration tweak within your Google Email Account .

How "more secure apps" help to protect your account?

Which level of access you're giving the client before you connect your Account.
Client access only a relevant part of your Account, like your email or calendar.
Connect your Google Account to the client without exposing your password.
Disconnect your Google Account from the client at any time.
 
Top