I know it is possible to send an email with a fake address to impersonate someone else. I seen automated emails coming from my friend email address that he sent to me but did not write himself.
I know email servers ask the email provider if they really sent the message and if it is no it tends to go into spam or is marked untrusted. How do i access this data in my app? I havent chosen an imap library and thats because i dont know which may support this.
This functionality is not supported by imap.
Some servers store information like this in the header of the mail (like spamassassin info or SPF checks) so that is available with any imap library but depends highly on the mail server the app is connecting to.
In general it's not possible with IMAP. IMAP is intended for reading email, not for sending. You may try to fake email sender when sending email via SMTP protocol.
This is exactly what spam senders do (and what mail servers tries to detected).
It used to easy. SMTP dialog follows:
S: MAIL FROM:<your.friend#example.com>
R: 250 OK
S: RCPT TO:<somene#example.com>
R: 250 OK
S: DATA
R: 354 Start mail input; end with <CRLF>.<CRLF>
S: Blah blah blah...
S: ...etc. etc. etc.
S: <CRLF>.<CRLF>
R: 250 OK
But now things are getting more interesting. There is still race of arms between those two - for example:
Attack
Try to submit false "FROM:" address during communication with SMTP server.
Defense: SMTP server may require you to authenticate and allow only 'from' address associated with your account.
Another attack
Try to use third party SMTP server that has no such rule.
Defense (third party SMTP server): Allow sending only emails with 'from' domains matches with 'own' domains.
Defense (recipient's SMTP server): Add SPF record to your domain. This records includes all hosts that are allowed to send email with sender in this domain. If the email is sent from not allowed host increase it's spam score or delete it.
Another attack
Infect computer which is allowed to send email for specified domain with virus and send emails using it.
Defense: Educate users and/or use good antivirus.
And so on... There will be always ways how to fake sender's email address and how to fake it. Check following links for more info:
RFC 821 - SMTP
So You'd Like to Send Some Email (Through Code)
Related
I am trying to convert our current email agent to send email with TLS. We use C# and I just used the following changes.
SmtpClient sclient = new SmtpClient();
sclient.EnableSsl = true;
and a callback method to validate server certificate.
On Testing the mail was sent/received successully, but both I and the receiving end cannot be 100% sure the the email was received encrypted. (I tried to use Fiddler but its not capturing the email)
Based on this http://luxsci.com/blog/how-you-can-tell-if-an-email-was-sent-using-tls-encryption.html, and the header as below
with ESMTP id s7JKErN9002462
(version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO);
Can we safely assume that the mail communication indeed was encrypted? or Should I make any other code changes so that I can be sure that the email is received or it failed? (I think this cannot be certain as it depends on the smtp host) ?
In the end you can always check the TLS connection using network sniffer software such as WireShark.
Of course if you only leave a connection open to the SSL port of the server, and you receive the server certificate, you can be pretty certain the mail did not appear from the blue sky anyway.
You can safely assume that if you are able to connect and send, that the tunnel you're delivering the mail to is secure.
The SmtpClient code is solid and you can trust it. If it fails to connect securely after you've asked it to, it throws an exception, so you'll know something is not like you were expecting.
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.
Can anyone point me in the right direction to how I would handle capturing bounced email info. I'm looking into writing an email campaign manager and would like the ability to report that data.
You can write an app to poll your bad mail folder to identify returned email. You should wait for sometime after sending the email before checking whether it is delivered or returned.
Bounced email is slang for a Non Delivery Report or NDR. Most smtp servers have their own ways to handle NDRs, typically via a BADMAIL folder.
So first of all, confirm what your SMTP server software does for NDRs. Then confirm that this is working correctly. I think that if an email fails to send, the sender will get notified .. but if the sender can't be notified (ie. do not reply email, etc) I think this is how it ends up in the BADMAIL folder.
Anyway - you need to find out and confirm that the software you're using handles NDRs. Once it does, it's easy to write some code to check that folder every 'whatever' or even put a filewatcher on it, and then parse the content of each file that is added to that folder.
Bounced email can be parsed and you can use that information to mark email address invalid or whatever. What smtp server are you using to send emails?
And can you be more specific about the kind of help you're looking for? It's not very clear if you have access to these bounds emails and if so are they in the bounced queue of your smtp server or are they in your email client's (outlook etc.) inbox.
I'm working in a mail client project using C#. I'm using both the POP and IMAP protocol to communicate with the server. The problem is than I can not figure out why when I want to get the UID for a message the result from the POP server and the IMAP server are different.
POP
C: UIDL 1
S: +OK 1 UID2-1269789826
and
IMAP
C: $ FETCH 1 (UID)
S: * 1 FETCH (UID 2)
S: $ OK Fetch completed.
Why the result for obtaining the UID is so different? In IMAP is another function for this?
Any help is welcome.
Thanks.
POP3 and IMAP are two distinct protocols. The UIDs used by these two protocols are not related and are not supposed to be the same at all. In fact, a POP3 UID is an arbitrary string while an IMAP UID is a 32-bit number (transmitted as string).
In theory, it is possible to write a mailserver that supports both IMAP and POP3 use the same UID for both protocols, but I'm not aware of any server that would actually do this. In practice, you have to treat POP3 UIDs and IMAP UIDs as unrelated values.
RFC 1939 (POP3):
The unique-id of a message is an arbitrary server-determined string, consisting of one to 70 characters in the range 0x21 to 0x7E, which uniquely identifies a message within a maildrop and which persists across sessions.
RFC 3501 (IMAP):
(Unique Identifier (UID) Message Attribute is) a 32-bit value assigned to each message, which when used with the unique identifier validity value (see below) forms a 64-bit value that MUST NOT refer to any other message in the mailbox or any subsequent mailbox with the same name forever.
Very important IMAP fact
This is what I learnt playing with GMail (I expect other systems to be the same):
Sent a message to my inbox
It has UID 45
Move the message to junk
It now has UID 5 (because UID is unique per mailbox)
Move it back to inbox
It now has UID 46
Move it back to junk
It now has UID 6
Get the idea...
I moved the messages using the GMail.com UI
As far as I can tell UID is only useful in finding the latest emails in a folder. You can run the command Search("UID 34:*) to get all messages in a folder with UID 34 or above.
But don't start using UID as a key to that message in a database or you'll end up with dupes.
I think I'm going to take the time received and hash it with the message contents to get a UID I can actually put into a database.
I created a new email box for general support questions. When I try to send an email through SMTP I receive the following error:
Mailbox unavailable. The server response was: No such recipient
I am able to email the box through Outlook and SMTP works when I send to other email address in the same domain.
The great thing about SMTP is that it's easy to spoof the conversation. The terrible thing about SMTP is also that it's easy to spoof the conversation. What makes this great is that if you want to figure out what's going wrong in a SMTP connection you can just "telnet mailhost 25" and start issuing SMTP commands like:
HELO example.com
MAIL FROM: <me#me.com>
RCPT TO: <him#him.com>
DATA
Subject: test message
From: Me <me#me.com>
To: Him <him#him.com>
test message
.
QUIT
Is your DNS configured properly? You need an MX record specifying which host handles incoming messages for that domain.
Btw, your post is missing some details, like which server you are using etc. That makes it hard to find where the problem is.
If you post the complete SMTP conversation (or at least what your client is sending) the answer will probably leap out at you.
Or, if you're speaking SMTP correctly, perhaps you're connecting to the wrong server. Does your client look up the DNS MX record to find the right SMTP host?
First, make sure the address is valid. Also, make sure the From address is valid (that may be your problem). Finally if those do not work, you should try setting the SMTP server explicitly.
Without a bit of a code sample, that's the best advice that I can come up with.
Does your company have multiple mail servers? No such recipient might be returned if you have multiple servers and the newly created account hasn't been pushed through yet.
I actually used Telnet to diagnose the problem (Thanks to Paul Tomblin for his post). I found out that our SMTP server uses GroupWise (we use Exchange as our main email client). I had to set up the address to relay to the GroupWise server as well.