Click here to Skip to main content
15,910,303 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have purchased a domain with registration , so I have now mail account of my own company , i wrote a function to send an email below is the code for email sending
protected void SendEmail(object sender, EventArgs e)
{
using (MailMessage mm = new MailMessage(txtEmail.Text, txtTo.Text))
{
mm.Subject = txtSubject.Text;
mm.Body = txtBody.Text;
if (fuAttachment.HasFile)
{
string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
}
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential(txtEmail.Text, txtPassword.Text);
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
}
}
Now as my email is omer@planrbme.com.pk as it is not a gmail account so instead of this line smtp.Host = "smtp.gmail.com"; what should i write

What I have tried:

I have tried with gmail it works but i want to use my own hosting account
Posted
Updated 20-Jul-16 3:41am
Comments
AdamASPGeek 20-Jul-16 23:10pm    
You need to contact your hosting provider. Each hosting provider have their own policy. I use localhost on my code here to send email via website.

Depends on your hosting service - they will tell you exactly what to use, but the code I use is here: Sending an Email in C# with or without attachments: generic routine.[^] and for Host in my web.config file I use:
XML
<add key="SMTPHost" value="LocalHost"/>
 
Share this answer
 
Contact the hosting provider and they will tell you the smtp server to use, and if you need to use a username and password, and if so what that username and password is, if you need ssl etc. Update your code to use the correct details that match your smtp server. This info can normally be found in the dashboard of your hosting.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900