发送邮件时出现问题.发生安全问题. [英] Problem in sending the mail. Security issue occuring.

查看:99
本文介绍了发送邮件时出现问题.发生安全问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我尝试通过本地Web服务发送邮件时,它会发送出去.但是当我在另一个项目中将其用作参考时.我收到了这个问题:

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"}]}


解决该问题应该怎么做?

SendEmail.cs的代码:(参考文件中包含dll)


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();

            // Set sender email address, please change it to yours
            oMail.From = "abc@gmail.com"

            // Set recipient email address, please change it to yours
            oMail.To = ToEmail;

            // Set email subject
            oMail.Subject = " Password";

            // Set email body
            oMail.TextBody = " Hi, your user name is : " + ToEmail + " and password is : " + password;

            // Your SMTP server address
            SmtpServer oServer = new SmtpServer("smtp.gmail.com");

            // User and password for ESMTP authentication, if your server doesn't require
            // User authentication, please remove the following codes.            
            oServer.User = "abc@gmail.com";
            oServer.Password = "123456";

            // If your smtp server requires SSL connection, please add this line
            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();

        }
    }
}


Business Logic中的代码是:


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 "This EmailID Does Not Exist";
                    return "False";
                }
                else
                {
                    SendEmail send = new SendEmail();
                    send.sendMail(CoordinatorEmailID, password);
                    //return "Password Send Successfully To Your EmailID";
                    return "True";
                }
            }
            catch (Exception e)
            {
                return e.ToString();
                throw;
            }
        }



webservice类包含:




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"}]}



该项目包含我的webservice的服务参考.

在此先感谢............



This project is containing the service reference of my webservice.

Thanks in advance............

推荐答案

1)在另一个简单的应用程序中检查SendEmail.cs的代码,以便您确认问题出在哪里,就像下面的代码以正常形式正常工作一样.将缺少的参数添加到您的代码中.

1) Check your code for SendEmail.cs in another simple application so you will confirm exactly where the problem is ,like following code is working fine in a normal form.add the missing parameters to your code.

MailMessage mail = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
if ((mailSettings != null))
{
    mail.To.Add(new MailAddress(Properties.Settings.Default.SendExceptionLogFromMailId));
    mail.IsBodyHtml = true;
    mail.Subject = Constants.ERROR_LOG_MAIL_SUBJECT;
    mail.Body = Constants.ERROR_LOG_MAIL_BODY;
    mail.From = new System.Net.Mail.MailAddress(Properties.Settings.Default.SendExceptionLogFromMailId);
    Attachment objAttachment = new Attachment(logFileZipLocation);
    mail.Attachments.Add(objAttachment);
    smtpClient.UseDefaultCredentials = false;
    smtpClient.DeliveryMethod = mailSettings.Smtp.DeliveryMethod;
    smtpClient.Credentials = new NetworkCredential("@gmail_id", "Password");
    smtpClient.EnableSsl = true;
    smtpClient.Host = "smtp.gmail.com";
    smtpClient.Port = 587;
    smtpClient.Send(mail);
}



2)手动检查邮件提供商是否在您的公司范围内.



2) Check manually if the mail provider is block or not in your firm.


您的代码必须在公司的Intranet下运行.
因此,它将显示这种类型的问题.
You code must be running under company''s intranet.
So, it will show this type of issue.


这篇关于发送邮件时出现问题.发生安全问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆