I created this email address "info#mydomain.com" and I want users be able to send email for me through my website.
Here is my code:
MailMessage mailObject = new MailMessage("a#b.com(this is fake email)", "info#mydomain.com", "contact us", "Test message");
SmtpClient smtpC = new SmtpClient("smtp server name");
smtpC.Send(mailObject);
Problem is I dont know what to write for smtp server name. How can I find what is my smtp server name?
This is the address of the SMTP server you want to use. e.g. smtp.gmail.com if you're using Gmail.
Search you email or hosting provider's website for "SMTP". Most likely they will have the details (smtp server name, port, ssl or not) soewhere in the FAQs.
Mostly the SMTP Server Name should be smtp.mydomain.com
Still it is best to contact the hosting provider
Open up a command prompt (CMD.exe)
Type nslookup and hit enter
Type set type=MX and hit enter
Type the domain name and hit enter, for example: google.com
The results will be a list of host names that are set up for SMTP
Related
As titled, is it possible to get Email Address from SMTP server by User name and password?
The reason I want to do this is because I know some smtp server supports open relay and some don't, for that reason, I see no meaning to provide the Sender and From email address.
But in the SmtpClient class it requires a Sender and From Email email address.
Instead I want to do it by getting the actual Email Address which is the User name associated to in the SMTP server.
Is it possible to do this?
I want to send mail automatically by special email account, but now, I only know the email address: tsp.monitor#qorosauto.com , and the password. so do you know how to get the SMTP server. below is my C# code:
SmtpClient client = new SmtpClient();
client.Host = "What is the SMTP Server, I want to get from email address, can you help me";
string account = "tsp.monitor#qorosauto.com";
string password = "Qoros111";
client.Port = 587;
client.EnableSsl = true;
client.Timeout = 100000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(account, password);
You find the SMTP server of a domain by taking the host part of the email address (qorosauto.com in your example) and looking up the MX record for it.
$ dig +short mx qorosauto.com
10 euq2.qorosauto.com.
5 euq1.qorosauto.com.
The number before the hostname indicate preference - in this case euq1.qorosauto.com is the preferred server to connect to.
Doing this in .Net is not straight-forward, as the answer to this question indicates: How to get mx records for a dns name with System.Net.DNS?
To add to the problems, many ISPs will filter your connection in the firewall and won't let you talk to any SMTP server except the ISPs one, which in turn will relay the mail to the recipient.
Essentially, you want to use your ISPs or organizations SMTP server - not the recipients MX.
Trial and error might get you there..
mail.quorosauto.com
smtp.quorosauto.com
www.quorosauto.com
smtp.gmail.com
If you've exausted every possibility you'll need to provide your own SMTP server. There are a few freebie servers:
http://freesmtpservers.com/
However if you are doing this professionally you probably want to use the SMTP server of your organization so you probably want to ask your boss or a colleague.
You may try mail.orosauto.com or smtp.orosauto.com. Login to you domain account and check mail settings. hopefully you can find the mail server details over there.
To find out the responsible mail server you have to ask the DNS. By using the web for example go to this nslookup page.
Normally you start at the domain server of your provider, but you can also start with a root-server (e.g. 198.41.0.4) and ask for the domain google.com and the query type MX - Mail exchange.
You'll get back a list of responsible dns server. Simply pick one out of the list (e.g. 192.26.92.30) and send the same query again to this server. Rerun this sequence till you'll get a list of type MX. Simply pick one address out of this list (maybe the first, maybe the one with the lost value in preference) and use this to establish your smtp connection.
That's the way how every mail server does its work. Now it is up to you to implement that into your application. ;-)
I have following piece of code, usiong which I am trying to send an email. I am using another server as SMPTClient.
MailMessage message = new MailMessage();
message.To.Add(toEmailId);
message.Subject = "test Subject";
message.From = new System.Net.Mail.MailAddress("myid#xyz.com");
message.Body = "This is a system generated email. Please do not reply";
SmtpClient smtp = new SmtpClient("anotherservername");
smtp.Send(message);
While debuggin, I get error at last line. The error is:
An attempt was made to access a socket in a way forbidden by its access permissions SERVER IP :25
I found out from internet that My firewall might be blocking me to access that server's port, or is there any setting, configuration which I have missed. Apparently the applications deployed on that server are able to send emails. I am still building one to test.
Some servers perform authentication and authorization by checking if you've connected to POP server some time before connecting to SMTP. You should try first connecting and authenticating with POP and afterwards connecting to SMTP.
Historically, email clients first checked and then sent emails in Send&Receive routines, so this was used as poor mans authorization. Take a look at wikipedia article about POP before SMTP.
Another issue which caused this for some people is how server address is provided to SmtpClient. You should use constructor which explicitly provides port number instead of appending it to IP/hostname. I.e.
instead of new SmtpClient("123.123.123.123:25")
use new SmtpClient("123.123.123.123", 25)
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);
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
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.
i am creating an email client that sends e-mail address from server ip instead of SMTP , i wrote that code:
SmtpClient server = new SmtpClient("50.23.128.66");
MailMessage msg = new MailMessage("from#yahoo.com", "tome#yahoo.com", "subject", "body");
server.Send(msg);
but when i run it , i get that error:
Unhandled Exception: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Relaying Denied.
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressColl
ection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
* By the way i am using Windows Server 2008 *
and i configured the smtp server to localhost and port 25 , but i don`t know what is that relying error .
If you are using you localhost to rely email, you should be using 127.0.0.1 or localhost instead of that ip address you posted in your code.
Relaying is the method the SMTP server uses to authenticate that it should route the email from a particular sender. An "open relay" means that there is no authentication and the SMTP server will send email sent from anyone. This is not a good practice and there are probably some mechanisms on this particular SMTP server to authenticates, such as a user name and password or even the IP address of the sender. Check with the administrator of the SMTP server to see what is required. I would think at a minimum you would need to set the user name and password, which you did not do in your code example.