Sending HTML formatted e-mail using QTP DOT Net factory. In the below code I have used Gmail account. You may try with other accounts also.
Dim vStUserName,vStPassword,vStServerName
vStUserName="Gmail Account Username"'Enter your Gmail Account User Name
vStPassword="Gmail Account Password"'Enter Your Gmail Account Password
vStServerName="smtp.gmail.com"'Gmail SMTP Server Name
vStFromAddress="FromAddress@gmail.com"'Enter valid From Address
vStToAddress="ToAddress@yahoo.com"'Enter Valid To Address
Set oCredentials=DotNetFactory.CreateInstance("System.Net.NetworkCredential","System",vStUserName,vStPassword)
Set oSMTPClient=DotNetFactory.CreateInstance("System.Net.Mail.SmtpClient","System",vStServerName)
Set oMessage=DotNetFactory.CreateInstance("System.Net.Mail.MailMessage","System")
Set oFromAddress =DotNetFactory.CreateInstance("System.Net.Mail.MailAddress","System",vStFromAddress)
oMessage.From=oFromAddress
oMessage.To.Add vStToAddress
oMessage.IsBodyHtml=True'If your message to be formatted with HTML, then make this property value as True or else False.
oMessage.Subject = "GMail Test"'Subject of your email
oMessage.Body = " This is the test text for Gmail email"
oSMTPClient.Port = 587
oSMTPClient.Credentials=oCredentials
oSMTPClient.EnableSSL = True
oSMTPClient.Send(oMessage)
'Kill All the objects
Set oMessage=Nothing
Set oFromAddress=Nothing
Set oCredentials=Nothing
Set oSMTPClient=Nothing
Hi, I am getting the below error if i run the above code. could you please suggest.
ReplyDeleteExternal object System.Net.Mail.SmtpClient::Send has thrown the following exception:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 74.125.93.109:587
Line (25): "oSMTPClient.Send(oMessage)".
Nagannadora,
ReplyDeleteAre you behind a company firewall? I had the same problem. I cannot connect outside of my own office using scripts like these. If you are at home, you may need to reconfigure your own firewall.
It didn't work for me either. The error was generated by the SmtpClient stating "The remote certificate is invalid according to the validation process". it seems to try and make a connection rather than send it. Can this be configured to use pop?
ReplyDeleteThank you
Hi. Nice One and Working fine. Could you please tell me how to add attachment in this?
ReplyDeleteHi. Really nice blog.
ReplyDeleteAsif Can you give some links for sending an email though OutLook using DotNetFactory