Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi All,
I am facing problem in sending mail functionality in window 7.
I am using vs2008,c# and asp.net 3.5.

I am using following code for sending mail..........

C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;

public static void SendMail(string from, string to, string subject, string body)
    {
        MailMessage mailMessage = new MailMessage();
        mailMessage.From = new MailAddress(from);
        mailMessage.To.Add(to);
        mailMessage.Subject = subject;
        mailMessage.IsBodyHtml = true;
        mailMessage.BodyEncoding = Encoding.UTF8;
        mailMessage.Body = body;
        mailMessage.Priority = MailPriority.Normal;

        // Smtp configuration for localhost / gmail 
        SmtpClient client = new SmtpClient();
        client.Credentials = new NetworkCredential("[DELETED]@gmail.com", "mukeshpa"); // enter your user name and password for gmail 
        client.Port = 587; //use 465 or 587 ports for gmail     //use 25          
        client.Host = "smtp.gmail.com";// for gmail            //use "127.0.0.1";
        client.EnableSsl = false; // true for gmail 

        MailMessage message = mailMessage;

        try
        {
            client.Send(message);
            Show("sending mail........");

        }
        catch (Exception ex)
        {
            Show("Sending fail.." + ex.ToString());
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        SendMail(txtFrom.Text, txtTo.Text, txtSubject.Text, txtBody.Text);
    }


please help or any suggestion for me.......
help will be greatly appreciated..........

thanks
mukesh


[edit]Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know - OriginalGriff[/edit]
Posted
Updated 25-Aug-11 22:35pm
v3

1 solution

Without the error message, it is difficult to tell, but from the comments, this might be wrong:
C#
client.EnableSsl = false; // true for gmail
 
Share this answer
 
Comments
mukesh_panth 26-Aug-11 5:00am    
Thank you Very Much.......its working. :-)

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