Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
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
Updated 8-Nov-11 22:18pm
v2

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
 
Share this answer
 
v2
Comments
Raghupathiraja 9-Nov-11 5:59am    
i am gets error in smpt server connection only...
Literally give the SMTP Host name: the outgoing mail server reference you would put into an outlook account setup:
C#
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.talktalk.net");




"i used this code..."
C#
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.[^]
 
Share this answer
 
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...
If you are sending mail through gmail
use "smtp.gmail.com" as host
 
Share this answer
 
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
member60 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...
you have to set the EnableSSl to True before you set the NetWork Credentials of your SMTP client. as:
C#
SmtpClient.EnableSsl = True
 
Share this answer
 
v2
 
Share this answer
 
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.
 
Share this answer
 
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?
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
 
Share this answer
 
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.
 
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