Hi,
When i am trying to send a mail through webservice locally it gets send. But when i am using it as a reference in another project. I get this issue :
{[{"Result" : "System.Security.SecurityException : System.Security.Permissions.SecurityPermission
at EASendMAil.6y.2l(UInt32 6m, Byte[] 6m, Byte[] 6m)
at EASendMail.4k.2N(string 6m, MailStyle 6m, Int64 6m, Int32 6m)
at EASendMail.SmtpMail.3D(MailStyle 6m)
at EASendMail.SmtpMail..ctor(String v)
at EASendMail.SendMail.sendMail(String ToEmail, String password) at...
The type of the first permission that failed was :
System.Security.Permissions.SecurityPermission
The Zone of the assembly that failed was : MyComputer"}]}
What should be done to solve this problem?
The code for SendEmail.cs : (The dll is included in the references)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EASendMail;
using System.Net.Mail;
namespace EPWSBL
{
public class SendEmail
{
public void sendMail(String ToEmail, String password)
{
SmtpMail oMail = new SmtpMail("TryIt");
EASendMail.SmtpClient oSmtp = new EASendMail.SmtpClient();
oMail.From = "abc@gmail.com"
oMail.To = ToEmail;
oMail.Subject = " Password";
oMail.TextBody = " Hi, your user name is : " + ToEmail + " and password is : " + password;
SmtpServer oServer = new SmtpServer("smtp.gmail.com");
oServer.User = "abc@gmail.com";
oServer.Password = "123456";
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
try
{
Console.WriteLine("Start to send email ...");
oSmtp.SendMail(oServer, oMail);
Console.WriteLine("Email was sent successfully!");
}
catch (Exception ep)
{
Console.WriteLine("Failed to send email with the following error:");
Console.WriteLine(ep.Message);
}
Console.ReadLine();
}
}
}
The code in Business Logic is:
public string wsForgotPasswordForCoordinator(string CoordinatorEmailID)
{
string emailid = CoordinatorEmailID;
try
{
string password = coordinator.getCoordinatorPassword(emailid).ToString();
if (password.Equals(null))
{
return "False";
}
else
{
SendEmail send = new SendEmail();
send.sendMail(CoordinatorEmailID, password);
return "True";
}
}
catch (Exception e)
{
return e.ToString();
throw;
}
}
The webservice class contains :
public string wsChangePasswordForCoordinator(string str)
{
String CoordinatorEmailID = string.Empty;
String OldPassword = string.Empty;
String NewPassword = string.Empty;
String[] para = str.Split('{', '}', '[', ']', ':', '"');
for (int i = 0; i < para.Length; i++)
{
if (para[i].Equals("CoordinatorEmailID"))
CoordinatorEmailID = para[i + 3];
else if (para[i].Equals("OldPassword"))
OldPassword = para[i + 3];
else if (para[i].Equals("NewPassword"))
NewPassword = para[i + 3];
}
EPWSBL.Coordinator CBL = new EPWSBL.Coordinator();
string result = CBL.wsChangePasswordForCoordinator(CoordinatorEmailID, OldPassword, NewPassword);
return result;
}
The webservice contains :
[WebMethod]
public string wsForgotPasswordForCoordinator(string strCoordinatorData)
{
ManageProfile MP = new ManageProfile();
string result = MP.wsForgotPasswordForCoordinator(strCoordinatorData);
string JSONresult = "{[{\"Result\":\"" + result + "\"}]}";
return JSONresult;
}
This error occur while at this statement:
MessageBox.Show(abc.wsForgotPasswordForCoordinator("{{\"CoordinatorEmailID\":\"abc@gmail.com\"}}"));
The error is :
{[{"Result" : "System.Security.SecurityException : System.Security.Permissions.SecurityPermission
at EASendMAil.6y.2l(UInt32 6m, Byte[] 6m, Byte[] 6m)
at EASendMail.4k.2N(string 6m, MailStyle 6m, Int64 6m, Int32 6m)
at EASendMail.SmtpMail.3D(MailStyle 6m)
at EASendMail.SmtpMail..ctor(String v)
at EASendMail.SendMail.sendMail(String ToEmail, String password) at...
The type of the first permission that failed was :
System.Security.Permissions.SecurityPermission
The Zone of the assembly that failed was : MyComputer"}]}
This project is containing the service reference of my webservice.
Thanks in advance............