Search code examples
c#asp.netemailsmtpmailto

Open client mail Outlook with "mailto" work only in debug mode but not after deployed on "localhost"


Hello here is my problem I face for a while. I do not understand why, but opening the email client does not work after deployed my web application on my post localhost.But however everything works in debug mode from visual studio!

Thank you in advance for your help;-)

Here is my simple code:

try
{
    string dataBaseName = string.Empty;
    string serverName = ttbx_ServerName.Text;
    //get item from radcombobox to make the body message
    foreach (RadComboBoxItem item in cbx_DbName.Items)
    {
        if (item.Checked)
        {
            dataBaseName += "[#] : " + item.Text + "\n";
        }
    }

    string Body = "Last name: " + ttbx_YourName.Text + "\nFirst name: " + ttbx_YourFirstName.Text + "\nServer Name: " + serverName + "\nDataBase(s) name: \n" + dataBaseName + "\nSID: " + getMd5Hash(ttbx_sidSqlServer.Text);
    string command = "mailto:[email protected]?subject=A.R.M.S%20Customer%20Key%20Request&body=" + Body.Replace("\n", "%0D%0A");
    Process.Start(command);
}
catch (Exception)
{
    lbl_Error.ForeColor = System.Drawing.Color.Red;
    lbl_Error.Text = "No smtp mail client found , please send manually the informations";
    lbl_Error.Visible = true;
}

Solution

  • You cannot execute the process (Process.Start) on the client because it will be thru web interface. It works in debug because it starts the process on your local computer but won't work with "real" clients.

    Instead you have to display a mailto link in your browser like this :

    <a href="mailto:[email protected]?subject=" + subjectFromCode + " id="email-link">Send Email</a>
    

    Edit

    If you want to programmatically run this you can do ti thru jquery :

    $(document).ready(function(){
       $("#email-link").click();
    });