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.
Related
I can send mail with a valid Office365 account using my C# web application to a list of opt-in addresses. So it is our own data source with our customers in it. The problem is that it is probably not received by our customers. I have send a mail from the info account to my own office365 account and pasted the headers in mxtoolbox and got a message that my local pc is blacklisted. even when it is using the smtp of office365. We have dkim enabled and spf in the dns. What else should I do to troubleshoot this?
Here is my simple C# code for sending the mail (which works, but might needs additional anti-spam stuff?)
SmtpClient sc = new SmtpClient();
sc.Host = "smtp.office365.com";
sc.Credentials = new System.Net.NetworkCredential(SmtpUsername, SmtpPassword);
sc.Port = 587;
sc.EnableSsl = true;
Should I add my home IP and from the office to the SPF dns entry, even when I am using the smtp of office365?
this is the value for Authentication-Results
dkim=none (message not signed) header.d=none;ouroffice365domain.com; dmarc=none action=none
Is that the cause for getting on the blacklist? Please note that I am not trying to send spam. It is a valid data source where people opted in for. We are just migrated to office365 and need to send a mailing to our customers from our custom web application. We are aware of the limitations (10k per day) and 1 mail every 2 sec.
edit will change this: https://stackoverflow.com/a/23409351/169714 because I just used the mail address and not the first and last name of the customer.
Not having DKIM setup is not going to get you blackisted, having it set up improperly can. Your HOME PC should have nothing to do with SPF, it's the lasting sending IP which should be OFFICE 365 IP. Did you validate your DKIM and SPF by sending an email to mailtest#unlocktheinbox.com or check-auth#verifier.port25.com?
I also don't think your LOCAL PC is blacklisted, it's the IP of your INTERNET Provider that is blacklisted. Unless you have a static IP it will change.
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)
It seems that when you use SmtpClient class and MailMessage to send emails, everything works fine. And it does send it. However, some servers, such as your business Exchange Server or Gmail.com or whatever services, sometimes reject these emails (because they could be phishing sites or spam sites?)
I'm using this and a lot of places reject the email I believe:
SmtpClient smtp = new SmtpClient
{
Host = smtpClient,
Timeout = 40000, // 40 seconds
DeliveryMethod = SmtpDeliveryMethod.Network
};
How do you work around this? Do you have to use login credentials to some recognized / white-listed server so that it is authorized and trusted email?
I could use something like GMAIL authentication, but my server should be allowed to send emails, it shouldn't have to rely on gmail.
Long ago there were many servers on the Internet that provided the service delivery of e-mail without asking too many questions about who was using the service.
Then came the SPAMMERS!.
A server that was sending mail freely around the world was no longer a benefactor of the internet, but a problem.
Nowadays it is increasingly difficult to find a server that sends mail on the Internet without asking for credentials.
Your e-mail server (smtp.yourbusiness.com or whatever you want) does not trust you.
When you ask it to send an email for you, it wants to know who you are.
SmtpClient smtp = new SmtpClient
smtp.Host = "smtp.yourbusiness.com";
NetworkCredential credentials = new NetworkCredential("your_user_name_on_smtpserver", "your_password_on_smtpserver");
smtp.Credentials = credentials;
are you setting the sender mail address and can your mail server be resolved by reverse dns lookup? Some spam filters distrust mail servers they can't reverse lookup. If you for instance make your mail server send mails using a bogus or foreign mail domain, spam filters will probably pick this up and filter your mail. If you have set up a SPF record for your domain and your sending mail server isn't in that record, mails from that server will also often be filtered by spam filters. Another reason could be an IP address from a range known to be dynamically assigned by internet providers. Mail servers sending from these address ranges are mostly spam bots and are therefore often also filtered.
To send GMail you need to specify a number of settings - yes you'll need to use authentication (GMail wouldn't open up their relay to everyone, or they'd get used for spamming).
If I recall correctly you need to send on TCP port 587, enable SSL, host to mail.google.com and provide a username and password on your SmtpClient to get Gmail to actually send it - neglecting one of those usually generates an email back from them telling you what you've forgotten.
Edit: Just to clarify on the username and password bit; you'd need to create a new NetworkCredential with the username and password for your GMail account, and set the Credentials property of your SmtpClient to that.
If i interpret your question correctly: the messages are sent our from your server, but they are trapped in the spamfilters at the receiving end?
If this is the problem, it has nothing to to with the way you are sending the messages but much more with the content of your message and the characteristics of your server. So it does not matter what credentials you use or if you send it with SmtpClient or any other class. Moving to Gmail does not help and Gmail has a limit to the number of messages you can send.
Spam filters like spam assassin use rules. Match too many: your message is considered spam.
Have a look here for an example:
http://spamassassin.apache.org/tests_3_3_x.html
So make sure your message does not get too high a score and it will go trough.
I am trying to write code to send a simple mail from asp.net page.
Confusion is over what to write under "smtp server", when I want to send mail using Microsoft Outlook 2007.
Two sets of code I'm trying:-
1.)
MailMessage objMail = new MailMessage();
objMail.From = "angenlina.jolie#compnayabc.com";
objMail.To = "brad.pitt#companyabc.com";
objMail.BodyFormat = MailFormat.Text;
objMail.Priority = MailPriority.High;
objMail.Subject = "Hi Sweetheart";
string smtpadd = "USA-LA-MAIL1.corp.hollwood.com";
SmtpMail.SmtpServer = "smtpadd";
SmtpMail.Send(objMail);
2.)
SmtpClient smtp = new SmtpClient();
smtp.Port = 25;
smtp.Host = "USA-LA-MAIL1.corp.hollwood.com";
smtp.Credentials = new NetworkCredential("username", "password");
MailMessage email_msg = new MailMessage();
email_msg.To.Add("brad.pitt#companyabc.com");
email_msg.From = new MailAddress("angenlina.jolie#companyabc.com");
email_msg.Subject = "test mail...";
email_msg.Body = "Hi SweetHeart";
email_msg.IsBodyHtml = false;
smtp.Send(email_msg);
Now my problem is what server name should I use for Microsoft outlook 2007(MS exchange server)?
Now my problem is what server name should I use for Micrsoft outlook 2007(MS exchange server)?
Are you sending email via MAPI (using their "Outlook profile") or via SMTP through an Exchange Server? They're not the same.
If you are sending through Exchange then the server will need to be configured to relay mail via SMTP. In which case, put the Exchange server in as the SMTP server.
If you're sending email via MAPI then you'll be using whatever mail server is configured in their "Outlook profile". Which could be SMTP, IMAP, Webmail (with a Hotmail connector or Gmail connector) or Exchange Server.
EDIT:
It sounds like you want to use the Exchange server via MAPI. Here is a good primer to the technologies involved.
Bear in mind that if you're configuring MAPI profiles from within the ASP .NET application you're going to pay attention to the service account the ASP .NET application runs as and that the MAPI is sometimes interactive and not suitable for service based applications.
You may be better off having an administrator configure the Exchange server to route email via SMTP (which is most likely is, unless you have a spam appliance in front of the server which handles SMTP).
try something generic i.e
Email Client setup information
IMAP server: imap.smtpserver.in
POP server: pop.smtpserver.in
SMTP server: smtp.smtpserver.in
Webmail
To access your email through a web browser visit http://webmail.smtpserver.in
smtpserver.in is your smtpserver host address.