i have use a sending mail code but problem is that exist when i have send mail offline it sending but when i have publish my website and then upload this website and then sending mail so a error is occur error is The transport failed to connect to the server.

my code is

i have used a claas
class name is MailSender.cs

using System.Web;
using System.Net;
using System.Web.Mail;
using System;
public class MailSender
{
    public static bool SendEmail(
        string pGmailEmail,
        string pGmailPassword,
        string pTo,
        string pSubject,
        string pBody,
        System.Web.Mail.MailFormat pFormat,
        string pAttachmentPath)
    {
        try
        {

            System.Web.Mail.MailMessage myMail = new System.Web.Mail.MailMessage();
            myMail.Fields.Add
                ("http://schemas.microsoft.com/cdo/configuration/smtpserver",
                              "smtp.gmail.com");
            myMail.Fields.Add
                ("http://schemas.microsoft.com/cdo/configuration/smtpserverport",
                              "465");
            myMail.Fields.Add
                ("http://schemas.microsoft.com/cdo/configuration/sendusing",
                              "2");
            //sendusing: cdoSendUsingPort, value 2, for sending the message using 
            //the network.

            //smtpauthenticate: Specifies the mechanism used when authenticating 
            //to an SMTP 
            //service over the network. Possible values are:
            //- cdoAnonymous, value 0. Do not authenticate.
            //- cdoBasic, value 1. Use basic clear-text authentication. 
            //When using this option you have to provide the user name and password 
            //through the sendusername and sendpassword fields.
            //- cdoNTLM, value 2. The current process security context is used to 
            // authenticate with the service.
            myMail.Fields.Add
            ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
            //Use 0 for anonymous
            myMail.Fields.Add
            ("http://schemas.microsoft.com/cdo/configuration/sendusername",
                pGmailEmail);
            myMail.Fields.Add
            ("http://schemas.microsoft.com/cdo/configuration/sendpassword",
                 pGmailPassword);
            myMail.Fields.Add
            ("http://schemas.microsoft.com/cdo/configuration/smtpusessl",
                 "true");
            myMail.From = pGmailEmail;
            myMail.To = pTo;
            myMail.Subject = pSubject;
            myMail.BodyFormat = MailFormat.Html;// pFormat;
            myMail.Body = pBody;
            myMail.Body += "http://www.cottonvyapar.com/bulletin.asp<br>";
            if (pAttachmentPath.Trim() != "")
            {
                MailAttachment MyAttachment =
                        new MailAttachment(pAttachmentPath);
                myMail.Attachments.Add(MyAttachment);
                myMail.Priority = System.Web.Mail.MailPriority.High;
            }

           // System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com:465";
            //System.Web.Mail.SmtpMail.SmtpServer = "SERVER";

            System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com";
            System.Web.Mail.SmtpMail.Send(myMail);
            return true;
        }
        catch (Exception ex)
        {
            throw;
        }
    }
}

and my web page name is sendbulletinmail.aspx
and is code is

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web;
using System.Web.Mail;
using System.Net;

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

      //  email.IsBodyHtml = true;
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        try
        {
            WebClient wc = new WebClient();
            string str = wc.DownloadString("http://www.cottonvyapar.com/bulletin.asp");

            MailSender.SendEmail(txtGmailId.Text, txtPassword.Text, txtTo.Text, txtSubject.Text,  str , System.Web.Mail.MailFormat.Text, "");
            lblError.Text = "Mail sent successfully.";
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }
    protected void txtTo_TextChanged(object sender, EventArgs e)
    {

    }
}

above this code i have sending a web page . so please help me.

Have you checked with your webserver provider that they allow outbound SMTP connections on port 465? since you are getting a transport error, that would be my first suggestion to validate.

commented: What they said... +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.