Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a code for mail sending Email sending code work fine in localhost but this code is not work when i upload this code in to the my web site my web site is www.smbresidency.com i use the gmail email sending code

This is My code

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Mail;
using System.Net;

public partial class Controls_ContactControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void SendMail()
    {
        var fromAddress = "infosmbresidency@gmail.com";// Gmail Address from where you send the mail
        var toAddress = YourEmail.Text.ToString();
        const string fromPassword = "*****";//Password of your gmail address
        string subject = YourSubject.Text.ToString();
        string body = "From: " + YourName.Text + "\n";
        body += "Email: " + YourEmail.Text + "\n";
        body += "Subject: " + YourSubject.Text + "\n";
        body += "Question: \n" + Comments.Text + "\n";
        var smtp = new System.Net.Mail.SmtpClient();
        {
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
            smtp.Timeout = 20000;
        }
        smtp.Send(fromAddress, toAddress, subject, body);
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            SendMail();
            lblMsgSend.Text = "Thanks For sending the mail";
            lblMsgSend.Visible = true;
            YourSubject.Text = "";
            YourEmail.Text = "";
            YourName.Text = "";
            Comments.Text = "";
        }
        catch (Exception) { }
    }
}



So Please Help Me
Thanks In Advanced

Mukesh Chandiwal
mukeshchandiwal@gmail.com
Posted
Updated 19-Aug-14 18:30pm
v2
Comments
Member 10398773 20-Aug-14 2:06am    
Whats the error message you getting?
mukesh chandiwal 20-Aug-14 2:20am    
There is no error
Member 10398773 20-Aug-14 2:34am    
I also am experiencing the same issue n my site.But the error on my side is The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first.Gmail tries to reject the authentication
mukesh chandiwal 20-Aug-14 4:37am    
you use smtp.EnableSsl = true;
smtp.Port = 587;

is for ssl connection
mukesh chandiwal 20-Aug-14 4:37am    
for gmail

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900