Smtp Email sending problem

Discussion in 'Email' started by llzzyy234, Aug 9, 2011.

  1. This code works fine in my local PC:
    public static void SendMailMessage(string subject, string body)
    {
    MailMessage mMailMessage = new MailMessage();

    // Set the sender address of the mail message
    mMailMessage.From = new MailAddress("[email protected]");
    // Set the recepient address of the mail message
    mMailMessage.To.Add(new MailAddress("[email protected]"));

    mMailMessage.Subject = subject;
    // Set the body of the mail message
    mMailMessage.Body = body;
    // Set the format of the mail message body as HTML
    mMailMessage.IsBodyHtml = true;
    // Set the priority of the mail message to normal
    mMailMessage.Priority = MailPriority.Normal;


    // Instantiate a new instance of SmtpClient
    SmtpClient mSmtpClient = new SmtpClient();
    mSmtpClient.Port = 587;
    mSmtpClient.Host = "mail.sgmedicaltour.com";

    System.Net.NetworkCredential autheninfo = new System.Net.NetworkCredential("postmaster", "mypassword");

    mSmtpClient.Credentials = autheninfo;
    //mSmtpClient.UseDefaultCredentials = false;
    mSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

    // Send the mail message
    mSmtpClient.Send(mMailMessage);
    }






    the error message is:

    Server Error in '/' Application.
    --------------------------------------------------------------------------------

    Security Exception
    Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

    Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    Source Error:


    [No relevant source lines]


    Source File: App_Web_saubipte.0.cs Line: 0

    Stack Trace:


    [SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
    System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
    System.Security.CodeAccessPermission.Demand() +61
    System.Net.Mail.SmtpClient.set_Port(Int32 value) +106
    MedicalTouren.Utility.MailHelper.SendMailMessage(String from, String to, String subject, String body) in MailHelper.cs:35
    MedicalTouren.MediEnquiryEn.btnSubmit_Click(Object sender, EventArgs e) in MediEnquiryEn.aspx.cs:33
    System.EventHandler.Invoke(Object sender, EventArgs e) +0
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
    System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
    System.Web.UI.Page.ProcessRequest() +80
    System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
    System.Web.UI.Page.ProcessRequest(HttpContext context) +49
    ASP.medienquiryen_aspx.ProcessRequest(HttpContext context) in App_Web_saubipte.0.cs:0
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
     
  2. The code works fine in local pc, but after I deployed, it prompt these error
     
  3. Ray

    Ray

    Last edited by a moderator: Oct 14, 2015

Share This Page