#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    25
    Rep Power
    0

    Custom mail sending error


    Hi

    I have C# code to send mail through gmail server. But when i want to use it in my server(win2003), it not work.
    I had another server(win2003) and this code worked correctly on it, and it work correctly in my local computer(win7).
    Do anyone know what is the problem?

    public class EMail
    {
    static string EmailFrom = "mymail@gmail.com";
    static string EmailDisplayName = "display name";
    static string Password = "myPassword";
    static string Host = "smtp.gmail.com";
    //static int Port = 587;
    static int Port = 465;

    static public bool SendMail(string Subject, string Body, string EmailTo)
    {
    try
    {
    //create mail.
    MailMessage message = new MailMessage();
    message.From = new MailAddress(EmailDisplayName + "<" + EmailFrom + ">");
    message.To.Add(new MailAddress(EmailTo));
    message.Subject = Subject;
    message.Body = "Stream, MediaTypeNames.Text.Html";

    //Create alternate view.
    string htmlBody = Body;
    AlternateView avHtml = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);

    message.AlternateViews.Add(avHtml);

    SmtpClient sc = new SmtpClient(Host);
    sc.Port = Port;

    sc.Credentials = new NetworkCredential(EmailFrom, Password);
    sc.EnableSsl = true;
    sc.Send(message);
    return true;
    }
    catch (Exception ex)
    {
    return false;
    }
    }
    }


    Best Regards.
    morteza
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    25
    Rep Power
    0
    Hi
    The server was Windows2003server-64bit, and the problem was 64bit. I change it to 32bit and it works fine now.
    Unfortunately .Net Framework not supported in win2003-64bit, completely.

    For more detail go to following link and read “.NET Application Services” section, and its checkpoint in under of table: “(2) Not supported in 64-bit versions of Windows Server 2003. ”
    http://technet.microsoft.com/en-us/library/cc758523(WS.10).aspx
    I hope this helpful

    Best Regards.
    Morteza.

IMN logo majestic logo threadwatch logo seochat tools logo