You can't 100% avoid getting these types of emails. Just don't open email attachments from senders you don't trust or are not expecting. You can always contact the sender to confirm the attachment if it's originated from someone you know.
I rarely ever see these virus attached emails as most all are auto sent to my junk folder.