Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Guys

I want to send an email without using gmail as smtp server!!!

Please Help Me guys :)

Thanks:)
Posted

Hi
I Hope That Help you ...

MailMessage MailMesaji = new MailMessage();
 MailMesaji.Subject = "Hello";
 MailMesaji.Body = " How are u";
 MailMesaji.BodyEncoding = Encoding.GetEncoding("Windows-1254");
 MailMesaji.From = new MailAddress("Email Sender @ Domain");
 MailMesaji.To.Add(new MailAddress("Email Reciever @ Domain"));
 SmtpClient Smtp = new SmtpClient("smtp.mail.yahoo.com");
 OpenFileDialog Ofd = new OpenFileDialog();
 if (Ofd.ShowDialog() == DialogResult.OK)
 {
 string Att = Ofd.FileName;
 Attachment ATTa = new Attachment(Att);
 MailMesaji.Attachments.Add(ATTa);
  
 }
  
 Smtp.Credentials = new System.Net.NetworkCredential("Email Sender @ Domain", "");
 Smtp.Send(MailMesaji);
 MessageBox.Show("mail Send");
 
Share this answer
 
v2
Comments
Harsha Dev 23-Jun-12 7:00am    
thanks man... but i need to send mail from host server... eg info@domainname.com will it work these kinds of emails
AshishChaudha 23-Jun-12 7:10am    
yes ofcourse it will work

Smtp.Credentials = new System.Net.NetworkCredential("info@domainname.com", "yourpassword");

Thanks
Ashish
Harsha Dev 23-Jun-12 7:30am    
will it work without password...??

:)
Harsha Dev 23-Jun-12 7:43am    
MailMessage MailMesaji = new MailMessage();
MailMesaji.Subject = (txtSubject.Text);
MailMesaji.Body = (txtBody.Text);
MailMesaji.BodyEncoding = Encoding.GetEncoding("Windows-1254");
MailMesaji.From = new MailAddress(txtEmail.Text);
MailMesaji.To.Add(new MailAddress("info@instant-freight.com"));
SmtpClient Smtp = new SmtpClient("smtp.mail.instant-freight.com");
Smtp.Credentials = new System.Net.NetworkCredential("info@instant-freight.com", "");
Smtp.Send(MailMesaji);
Response.Write("mail Send");

i am using this code in button click Error Sending Failed :(
 
Share this answer
 
Hi.....
use this code....
C#
private void Mail_sen()
    {
        try
        {
            string bBody = mailmsg();

            string email = TextBox4.Text;
            string sSub = "Contact_Us";
            SendMailmsg(bBody, email, email, email, sSub, "sendcc");
            //lblerror.Text = "Mail Sent Successfully.";
            //lblerror.ForeColor = Color.Green;
        }
        catch (Exception ex)
        {
            //lblerror.Text = "Send Email Failed.";
            //lblerror.ForeColor = Color.Red;
        }
    }
 
 private string mailmsg()
    {
        StringBuilder strHTML = new StringBuilder();
        strHTML.Append("<table width="70%">");
        strHTML.Append("<tr><td width="100%" colspan="2">Dear  abc </td></tr>");

        strHTML.Append("<tr bgcolor="cayn"><center><table><tbody><tr><td width="100%" colspan="2">CONTACT </td></tr></tbody></table></center></tr>");
        strHTML.Append("<tr><td width="20%">Name : </td><td width="80%">abc</td></tr>");
        strHTML.Append("<tr><td width="20%">Email ID : </td><td width="80%">abc@gmail.com</td></tr>");
        strHTML.Append("<tr><td width="20%">Phone No : </td><td width="80%">999999999</td></tr>");
        strHTML.Append("<tr><td width="20%">Comments : </td><td width="80%">hi this code try</td></tr>");

        strHTML.Append("</table>");
        return strHTML.ToString();
    }
	
	    public static string SendMailmsg(string body, string msgto, string cc, string msgfrom, string sub, string cond)
    {
        string status = "fail";
        try
        {
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            message.Body = body;
            message.IsBodyHtml = true;
            if (cond == "notsendcc")
            {
                message.To.Add(msgto);
            }

            if (cond == "sendcc")
            {
                message.To.Add(msgto);
                message.CC.Add(cc);
            }
            message.From = new System.Net.Mail.MailAddress(msgfrom);
            message.Subject = sub;
            // message.ReplyTo = new MailAddress(repto.Trim());
            message.Priority = System.Net.Mail.MailPriority.High;
            SmtpClient SmtpMail = new SmtpClient();
            {
                SmtpMail.Host = "smtp nost name";
                SmtpMail.Port = Prot no;
                //SmtpMail.Port = 25;
              //  SmtpMail.EnableSsl = false;
  SmtpMail.EnableSsl = true;
                SmtpMail.UseDefaultCredentials = true;
                SmtpMail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                SmtpMail.Credentials = new System.Net.NetworkCredential("email_id", "pass******");
                SmtpMail.Send(message);
            }
            message = null;
            status = "success";
        }
        catch (Exception ex)
        {
            throw (ex);
        }
        return status;
    }
 
Share this answer
 
v2
Comments
Harsha Dev 23-Jun-12 7:44am    
thanks but i want to send mail without using gmail smtp... :)

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