I have my own (Windows) VServer with my own domain and mx record.
Now I want to build a simple mail listener, which listens to all incoming mail to "*#mydomain.com" and stores it in a database.
I spent probably an hour googling, searching stackoverflow and informing about protocols, but I haven't found anything quite close to what I want to achieve.
What I don't want to do:
Receive mails via IMAP/POP3/Exchange from an existing mailbox server
Send Mails via SMTP
Install any mailbox server software, e.g. Mercury Mail
Related
What happens when the outgoing mail server is not part of the local domain? For example, I work for company xyz.com and our smtp server is mail.xyz.com. We host client sites in a multitennant application. We allow our users to point to their own smtp server using email configurations we store in our database.
The code we use to send emails loads the configuration with the smtp information and the authorization needed to send an email on behalf of our clients through their email system.
Currently we are running into concurrency issue that is causing timeouts for various clients when notifications are being processed. They are currently configured to be sent immediately. I've read that moving to the local pickup directory can solve this issue.
I am concerned if I specify a path like C:\Temp\Mail but use an SMTP connection to a clients mail server is that going to work? Doesn't the email being created and sent from the pickup location need to be on the same domain as the smtp server?
How will the clients SMTP server know .eml file has been generated for their domain and needs to be sent out without having to change our client's environment? If someone can provide any information as to how the SMTP and Specified Pickup Locations work I would greatly appreciate it.
The basic operation of an SMTP server in this sense is to monitor a specific set of folders and perform an action when an event occurs. Where your concern is is in that a file dropped into the pickup location is parsed and sent.
The basic SMTP operation allows any email server to send any email regardless of the domain that the email says it is from. This obviously caused issues with fraudulent emails and has been mitigated originally by Designated Sender and further extended via SPF, DIM, and DMARC.
So what your client would need to do is to have their SMTP setup properly and configured for your email domain(s). On your end it would be recommended to only allow the Designated Senders generate emails, and set up SPF etc for those clients as well
Microsoft has a good article on the SMTP basics How SMTP Works
Google has plenty of lists for SPF, DKIM, and DMARC as well.
I know there many articles on web regarding sending emails from code/C# and I have read many of them before posting here, but I still don't see a clear picture of how to implement my requirements:
Scenario:
My application on mydomain.com receives a request to send some kind of email (from: someone#mydomain.com, to: someone#gmail.com/anyother.com).
I need to make some manipulations on email content.
After I modified a message, I need to send it directly to recipient.
Under directly to recipient I mean that I want to send it to recipient by our servers and not using some kind of SMTP service/relay.
So as I understand I can install some SMTP software on our servers and send using System.Net.Mail.SmtpClient to our server and it will deliver it to recipients using SMTP Relay or some other way that coded inside that software...but, I would like to make it without using SMTP Server software...
Till now I found that I need to discover MX record for recipients domain, so let's say I found MX record for gmail.com (gmail-smtp-in.l.google.com), but how do I send email to that MX Record from my own C# code?
Does System.Net.Mail.SmtpClient suitable for this task?
Where I can find examples of how to do it?
From my previous expirience with SmtpClient, I need to provide SMTP server address (optionaly port), credentials, but in my case, of course I do not have credentials and I'm not sure how to get the correct port (does all servers from MX records has port 25?).
Thanks!
How do I prevent MS Exchange users from forwarding or copying a message sent via System.Net.Mail?
Not possible unless you write an Outlook plugin and even if you do, a determined user will always be able to do it one way or another.
You can't. If the email message was sent via Exchange rather than SMTP, you might be able to...with a server-side Exchange plugin/extension. But if the mail is sent via SMTP and is outside the Exchange server, you're SOL. The mail message is nothing more than a simple text file. Which see RFC 5322: Internet Message Format.
Further SMTP itself is a store-and-forward protocol. Every mail server involved in moving the message from sender to recipients gets a copy of the message and can keep it around.
i am used gmail to send mails from my asp.net page , but i want a method to Confirm ( make sure ) that the message successfully arrived to the recipients ( i add some recipients to BCC )
anybody can help me ??
there are two ways
request a read receipt
embed image to mail body
but as I know google doesn't support them. anyway search about those two ways.
I think you can not do this from your "send code" directly. I guess you need to use a some POP3 or IMAP api to see if there are a new email was recieved by recipient.
For example, you can only test if SMTP-server has accepted o rejected you message (spam-reason, auth error), but your cannot check if email was recieved by opponent
Or you maybe can use a "autoanswer" feature of you email client
With standard RFC822 email there's really no way to confirm receipt. To send a message, the mail client will talk to an SMTP server. The server may reject gross problems (ex. malformed email addresses). The server will attempt to forward the message to the destinations but somewhere along the way the message could fall on the floor. And of course the message could wind up in the destination mailbox but perhaps no one will read it.
Typically if delivery fails you'll eventually get a bounce message but this won't occur at the same time mail is delivered.
You have to use the some POP3 (protocol) library to check the recipient has received your email. POP3 is what you can use for retrieving mail, but it does not have support for PUSH either (so you would have to poll for mail).
The IMAP4 IDLE extension is what most refer to as PUSH mail - so you will need to find a library for C# that supports IMAP4 IDLE.
Check this link Using C# .Net Libraries to Check for Imap Messages
and also check this Accessing IMAP in C#
Keep in mind that your mail server also needs to have IMAP4 and IMAP4 IDLE enabled. Some mail servers don't support it, and will have to use POP3 polling.
Is it possible to send an email in C# console, without needing and SMTP server?
Edit:
Why do I need another SMTP server? Can not I use my localhost machine as a server..?
Edit:
I just need to send an email from with my domain name, for example abc#mydomain.com
Is that possible? what do I need to do this in my C# program... I do not care about receiving emails, I just care about sending them....
Thanks
You don't have to depend on a local SMTP server if you don't have one. However, you will have to connect to a SMTP server anyway. Here is why.
You must achieve the following steps:
Determine what is the mail exchange servers of a given domain.
Connect to that mail exchange server and deliver your mail.
Those steps are normally done by your local SMTP server. Another advantage of your local SMTP server is that it will handle its queue and continue to try to deliver your email if it fail.
How to determine the MX records of a give domain.
I suggest you to have a look at this answer. Basically, you have to do a query on a DNS server to get the list of MX records of the domain name of the email address you want to send an email to.
How to connect to a mail exchange server
Well the answer will disappoint you. Exactly like you connect to your local SMTP server. Using the TcpClient, you connect to one of the mail exchange server you got at the previous step on port 25 and start the delivering process using the SMTP protocol.
The trick here is that you must handle multiple MX servers. They are usually listed with a preference. If the first one is unreachable, you try the next one and so on...
That is something your SMTP server can handle for you too.
If you really want to build that logic yourself, please have a look at the DirectSend method of the SmtpClient class of this open source project I'm involved in.
As #TomTom points out, the entire mail infrastructure depends on SMTP. What you can do is to skip the output (relaying) SMTP server and send the message directly to the receiving SMTP server.
To do that you need to create some kind of queuing mechanism (there is no guarantee that the receiving SMTP server can serve you when you try to connect) and that you can look it up.
MX records are entries stored in DNS servers and are used to find SMTP servers. You can find a article here with a MX lookup example: http://www.codeproject.com/KB/IP/dnslookupdotnet.aspx
However, I DO recommend that you install a local SMTP server and let it take care of the above mentioned issues.
Yes, Basically figure out where to sent the email and send it. i.e. a DNS MX lookup for the domain to find out the SMTP server.
Every email needs an SMTP server on the receiving side.
You can use gmail or yahoo SMTP server, if you don't want to install your own.
Before sending mail you first need to authenticate, otherwise sending mail is not going to possible.
You need access to some kind of email server to send your email, and your email will most likely pass through one or more SMTP servers on it's way to the recipient. However, the email server you connect to might let you send the email without using SMTP. For example, Exchange might let you use MAPI or CDO to send emails. Though I think that CDO is not officially supported by .Net and simple MAPI is deprecated in Windows and should not be used. You might be able to use Exchange Web Services as described here: Introducing the Exchange Web Services Managed API 1.0
If you have another email server than Microsoft Exchange, that server might have some kind of API you can use.
Something I do often is to create gmail account and send through that account.
You just need your SmtpClient to connect to the host smtp.gmail.com on port 587 with the username, password, and enableSSL property set to true.