Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i sending a mail but i am getting problem while sending the mail's plz help me
my code is -
C#
protected void Btn_Submit_Click(object sender, EventArgs e)
    {
        string style = "<span style="color:Green;font-weight:bold;font-size:14px;">";
        string uid = System.Configuration.ConfigurationSettings.AppSettings["gmailid"].ToString();
        //string mailfromid = System.Configuration.ConfigurationSettings.AppSettings["noreplyid"].ToString();
        string mailfrompwd = System.Configuration.ConfigurationSettings.AppSettings["noreplypwd"].ToString();

        string Body = "You Have Subscribe E-Paper...";
        string Subject = "New Subscription";
       // Email(mailfromid, mailfrompwd, uid, Body, Subject);
        Email(uid, mailfrompwd, uid, Body, Subject);
    }

    public void Email(string from, string frompwd, string to, string body, string subject)
    {
       
        MailMessage mail = new MailMessage();
        mail.From = new MailAddress(from);
        mail.IsBodyHtml = true;
        NetworkCredential mailAuthentication = new NetworkCredential(from, frompwd);
        SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
        smtp.EnableSsl = true;
        smtp.UseDefaultCredentials = false;
        smtp.Credentials = mailAuthentication;
        mail.To.Add(new MailAddress(to));
        mail.Subject = subject;
        mail.Body = body;
    }</span>
Posted
Updated 14-Dec-13 1:56am
v3
Comments
OriginalGriff 14-Dec-13 7:39am    
What problem?
Is there an error message?
What does happen?
What doesn't happen?
Zoltán Zörgő 14-Dec-13 7:50am    
I am quite sure, this in not C code... - update you tags
It looks good, so please provide further details about your exact issue...
joginder-banger 14-Dec-13 7:58am    
what type of error you getting??

1 solution

Just a guess, but does nothing happen when you call that?

If so, then perhaps you should consider actually sending the email, instead of constructing the mail class instance and then discarding it at the end of the method...
Either:
1) Add this at the bottom of the Email method:
C#
smtp.Send(mail);

Or
2) See here for a pre-built method: Sending an Email in C# with or without attachments: generic routine.[^]
 
Share this answer
 

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