Click here to Skip to main content
12,696,493 members (30,462 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL-server-2005 C# ASP.NET , +
hi...
i got a code for send email to mail...
but i dint know how to give the smtphost name...

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost");

can u say how to do this ?
Posted 8-Nov-11 23:09pm
Updated 8-Nov-11 23:18pm
sravani.v15.9K
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

See this

How to send email through asp.net[^]

EDIT --->

To send email you need one host. If your company is having such configured host then ask concerned person for host address and credentials.

If you dont have any such own host then you can use gmail host server.
to send mail using gmail server check the above link
  Permalink  
v2
Comments
Raghupathiraja 9-Nov-11 5:59am
   
i am gets error in smpt server connection only...
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Literally give the SMTP Host name: the outgoing mail server reference you would put into an outlook account setup:
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.talktalk.net");




"i used this code..."
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
        message.To.Add("training@bellatrix.in");
        message.Subject = "This is the Subject line";
        message.From = new System.Net.Mail.MailAddress("raghupathirajamca@gmail.com");
        message.Body = "hi";
        System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
        smtp.Send(message);


"it showing error at last line ya"


The chances are that the error is actually caused because gmail want's authentication - it needs to know you are you, and not me trying to send messages from your account. This means you need to set the Credentials field.

Have a look at this tip: it contains a generic email routine: Sending an Email in C# with or without attachments: generic routine.[^]
  Permalink  
v2
Comments
Raghupathiraja 9-Nov-11 4:26am
   
i dont know exactly what to do?
can u say ?
OriginalGriff 9-Nov-11 4:35am
   
No! :laugh:
I do not know what EMail server you are using, so I cannot even give you a clue.
You need to see if the email provider you are using provides FAQ, or sent you an email at some point. They don't exactly hide this information!
Raghupathiraja 9-Nov-11 4:50am
   
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("training@bellatrix.in");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("raghupathirajamca@gmail.com");
message.Body = "hi";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.Send(message);
i used this code...
it showing error at last line ya
OriginalGriff 9-Nov-11 5:00am
   
Answer updated
Raghupathiraja 9-Nov-11 5:03am
   
thanks ya...
Khan Sarfraz 9-Nov-11 5:17am
   
from django.core.mail import send_mail, BadHeaderError

def send_email(request):
subject = request.POST.get('subject', '')
message = request.POST.get('message', '')
from_email = request.POST.get('from_email', '')
if subject and message and from_email:
try:
send_mail(subject, message, from_email, ['admin@example.com'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return HttpResponseRedirect('/contact/thanks/')
else:
# In reality we'd use a form class
# to get proper validation errors.
return HttpResponse('Make sure all fields are entered and valid.')
Khan Sarfraz 9-Nov-11 5:22am
   
private void Page_Load(object sender, System.EventArgs e)
{
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here

SmtpMail.SmtpServer = "mail.mycompany.com"; //your real server goes here
SmtpMail.Send( mail );
}
Khan Sarfraz 9-Nov-11 5:23am
   
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("training@bellatrix.in");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("raghupathirajamca@gmail.com");
message.Body = "hi";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.Send(message);
i used this code error got in last line
Raghupathiraja 9-Nov-11 5:57am
   
this is i posted knew?
can u answer for it?
Raghupathiraja 9-Nov-11 6:14am
   
protected void Button1_Click(object sender, EventArgs e)
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text);

System.Net.Mail.SmtpClient mysmtp = new SmtpClient("192.168.1.9");
try
{
mysmtp.Send(msg);
Label1.Text = "mail sent";
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
i used this also...
its showing failed mail sending
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

If you are sending mail through gmail
use "smtp.gmail.com" as host
  Permalink  
Comments
Raghupathiraja 9-Nov-11 4:34am
   
is it enough ah?
thank u
Raghupathiraja 9-Nov-11 4:51am
   
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("training@bellatrix.in");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("raghupathirajamca@gmail.com");
message.Body = "hi";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.Send(message);
i used this code error got in last line
Raghupathiraja 9-Nov-11 4:54am
   
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. lt8sm11626059pbb.0 "
got this error when i click the button
PKamaji 9-Nov-11 5:04am
   
check the solution i have sugested
Raghupathiraja 9-Nov-11 5:13am
   
in my code where i want to give this line...
dont mistaken...
Member 11144052 11-Oct-14 16:31pm
   
plz send solution makbuldon@gmail.com
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

you have to set the EnableSSl to True before you set the NetWork Credentials of your SMTP client. as:
SmtpClient.EnableSsl = True
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 7

  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Exactly as you have shown above, and is described here[^]. However, you need to know the host name in advance, since the software cannot guess which host you are allowed to use.
  Permalink  
Comments
Raghupathiraja 9-Nov-11 4:19am
   
how to know the host name?
how to find it?
can u say yar?
Richard MacCutchan 9-Nov-11 4:40am
   
Ask your service provider; how else can you find it?
Dave Quecke 16-Jan-16 22:57pm
   
Isn't there a default I can find on most machines?
Richard MacCutchan 17-Jan-16 2:57am
   
No, your SMTP hostname is given by the email provider.
Dave Quecke 17-Jan-16 12:09pm
   
But assuming the client machine has email service already and was already given the hostname, can't I find it somewhere on the machine programatically?
Richard MacCutchan 17-Jan-16 12:35pm
   
Well I guess you could use one of the network calls to see who is listening on any of the commonly used ports for email. however, very few client PCs have SMTP servers running on them. Most people use one of the commonly available sevices from people like Google, Yahoo, Miscrosoft etc.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 173.194.79.108:587
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6)
at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback)
at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
--- End of inner exception stack trace ---
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at WindowsFormsApplication2.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\jagan\Desktop\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs:line 33





that is the error i got//



my code was---


MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

mail.From = new MailAddress("ait90510@gmail.com");

mail.To.Add("mail.at100@gmail.com");
mail.Subject = "Name of subject";

mail.Body = "mail with attachment";

SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("myuserid", "password");
SmtpServer.Send(mail);




Anybody Please Help...................................................................


my id =mail.amit100@gmail.com
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 8

Hope this will help...


Open your Command Prompt and type

"nslookup" and press Enter

it will show you your server name with the server address.

Thank you.
  Permalink  

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


Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 4 Sep 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100