-4

i am trying to send email from c# windows application and i need SMTP Server Address to send email but i don't know about SMTP Server Address, what is SMTP Server Address, how to get SMTP Server Address and how to use it.

this is the code:

System.Web.Mail.MailMessage message=new System.Web.Mail.MailMessage();
message.From="from e-mail";
message.To="to e-mail";
message.Subject="Message Subject";
message.Body="Message Body";
System.Web.Mail.SmtpMail.SmtpServer="SMTP Server Address";
System.Web.Mail.SmtpMail.Send(message);
John Saunders
  • 157,405
  • 24
  • 229
  • 388
VICKY Shastri
  • 133
  • 2
  • 3
  • 12
  • 1
    [Sending E-mail using C#](http://stackoverflow.com/questions/449887/sending-e-mail-using-c-sharp) – Pradeep Sanjaya Sep 19 '12 at 01:31
  • 1
    [Sending email in .NET through Gmail](http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail) [Dummy SMTP Server for testing apps that send email](http://stackoverflow.com/questions/1006650/dummy-smtp-server-for-testing-apps-that-send-email) – Pradeep Sanjaya Sep 19 '12 at 01:33

2 Answers2

1

What Mail Server are you trying to use??? usually you can just google SMTP or POP3 or whatever protocal your looking for and it will give you the port, server and all the extra information you need to connect to it.

For example:

http://support.google.com/mail/bin/answer.py?hl=en&answer=13287

Ccorock
  • 872
  • 9
  • 35
0

First, the System.Web.Mail namespace utilities are marked as 'obsolete' and should not be used. Instead, you should use System.Net. In that namespace there is a 'MailMessage' and an 'SmtpClient' class that will do the job you are trying to do.

Next, an SMTP server is a process that runs on a computer, which, when connected to the inetrnet, can listen for, and respond to, incoming requests which use a particular protocol on a particular port. You can think of an SMTP server as the machine at the post office that sorts and routes the mail to the appropriate mailbox.
.
An SMTP server has an address, just like everything else on the internet that needs to communicate with anything else. The address is used to send your mail message to the right machine, on the right communication channel. you could think of it as its phone number, and your mail message a text that will be sent to it.

Next, the address you are looking for, last time I checked, was: smtp.gmail.com. So, considering that you need to stop using System.Web.Mail, and considering that your address may be smtp.gmail.com, here is what your code should look like:

        // setup mail message
        MailMessage message = new MailMessage();
        message.From = new MailAddress("from e-mail");
        message.To.Add(new MailAddress("to e-mail"));
        message.Subject = "Message Subject";
        message.Body = "Message Body";

        // setup mail client
        SmtpClient mailClient = new SmtpClient("smtp.gmail.com");
        mailClient.Credentials = new NetworkCredential("youraccount@gmail.com", "yourGmailPassword");

        // send message
        mailClient.Send(message);

Also, here is a decent looking article on using gmail as your smtp server: How to use Gmail as your SMTP server

Also, if gmail does not work for you, you can use the smtp server of your internet provider. They will usually have their smtp address lurking on their website somewhere to be helpful to customers who want to setup their email program. You can also look in Outlook under account settings if you cannot find it somewhere else, if you use anything besides gmail, you should find one there.

Lastly, keep in mind, email cannot be sent without using an smtp server which is willing to receive and dispatch your maill message. In general this is something like gmail, or the smtp server of your internet provider, and the address will normally be: smtp.providername.com. However, gmail, for example, requires your account credentials for the smtp server to allow your message to be received and dispatched.

dylansweb
  • 654
  • 4
  • 8