Showing posts with label Mail Sending from GoDaddy. Show all posts
Showing posts with label Mail Sending from GoDaddy. Show all posts

Thursday, January 2, 2014

Mail Sending from GoDaddy(without any issue)

Mail Sending from GoDaddy Hosted Website(without any issue)

Friends I had a mail sending functionality in my website but once its hosted in GoDaddy,I come across many issues(related to permissions,secured connection..etc) which I have solved and sharing with you,just do it...

Since I am using my web domain email by creating, so create your mail in the given domain from godaddy,and follow the below steps


 Step1:Declare Delegate
delegate void idlesendemail(string emailbody, string destination);

 Step2:On Submit Code
       protected void btnSubmit_Click(object sender, EventArgs e)
       {
              string strReceivingMailAddress = ConfigurationManager.AppSettings.Get("ReceivingMailAddress");
              string body = "<html>";
               //Write your entire Html code with design to send
              body = body + "</html>";
        idlesendemail d = new idlesendemail(AsyncInstutesub);
        d.BeginInvoke(body, strReceivingMailAddress, null, null);
    
ClientScript.RegisterStartupScript(typeof(Page), "Success", "<script>alert('We Have Received your Request We Will Contact you soon..');</script>");
       }

Step3:Write Method For Sending Mail

    private void AsyncInstutesub(string emailBody, string destination)
    {

        try
        {
            MailMessage message = new MailMessage();
            message.From = new MailAddress(ConfigurationManager.AppSettings["FromEmail"].ToString());
            message.To.Add(new MailAddress(destination));
            message.CC.Add(new MailAddress(ConfigurationManager.AppSettings["ccmail"].ToString()));
            message.Subject = "Contact Request";
            message.Body = emailBody;
            message.IsBodyHtml = true;
            System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();
            mailClient.Port = int.Parse(ConfigurationManager.AppSettings["Port"].ToString());
            System.Net.NetworkCredential basicCrenntial = new         System.Net.NetworkCredential(ConfigurationManager.AppSettings["FromEmail"].ToString(), ConfigurationManager.AppSettings["FromEmailPassword"].ToString());
            mailClient.EnableSsl = bool.Parse(ConfigurationManager.AppSettings["ssl"].ToString());
            mailClient.Host = ConfigurationManager.AppSettings["Hostname"].ToString();
            mailClient.UseDefaultCredentials = false;
            mailClient.Credentials = basicCrenntial;
            mailClient.Send(message);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

Step4:Include in web.config

                <add key="FromEmail" value="yourmail@yourgodaddywebsitedomain.com"/>
                      <add key="FromEmailPassword" value="yourmailpassword"/>
              <add key="Port" value="80"/>
              <add key="ssl" value="false"/>
              <add key="Hostname" value="smtpout.asia.secureserver.net"/>
                 <add key="Check" value="Y"/>
              <add key="ccmail" value="othermail@atanydomain.com"/>