You should use the Montoya method, which I recently learnt from Pablo Simón:
Hello. My name is Iñigo Montoya. You killed my father. Prepare to die.
This is a famous line from the 1987 film The Princess Bride (don't worry, you're probably too young), and it also happens to be a great way to write an effective email. If you were emailing me about one of my classes or to request a copy of one of my papers, it might look something like this:
Hello. You always greet the recipient! "Dear Rafael" is enough. Things like "Hi there" are a little too informal, and an email without a greeting can seem sloppy and rushed.
My name is Iñigo Montoya. If this is our first communication, you tell me your name. "My name is Joe Bloggs".
You killed my father. You tell me if and how we know each other. Whichever is relevant: "I'm a second year at Queen's", "I'm a part C student in the maths department", or "I'm in your B6.1 class on Wednesdays".
Prepare to die. Now that you've said hi, and you've told me who you are, comes the important part. Tell me what you want, short and to the point. "Could we please cover Fourier stability analysis in the class tomorrow?", or "Would you be willing to supervise a part B dissertation?", or "Could you share a PDF of your article?". This doesn't have to just be one sentence, but it's best to be direct.
Bonus points. You might even say goodbye! "Kind/Best regards" is pretty standard, "Yours sincerely" is quite formal, and I personally favour "Thank you" when I'm making a request.
All in all, your email might look something like:
My name is Joe Bloggs. I'm in your B6.1 class on Wednesdays; I was wondering if we could cover Fourier stability analysis in the class tomorrow?
My name is Joe Bloggs. I'm a second year at Queen's College. I would like to read your JCP article from 2022, but cannot get access through my library. Could you please share a PDF copy?
If you've ever emailed a lecturer and not had a response, a likely reason is that your email got lost in their inbox. Lecturers, like everyone else, get many emails, of which few are relevant. Most of us will try to purge our inboxes of anything which is not directly relevant to us (minutes of departmental meetings, updates from journals, spam...), and sometimes an important message will be deleted or archived by mistake. Annoying as it is, try not to take it personally.
Of course, you can insist. If you make a request and hear nothing back, it is perfectly acceptable to follow up, though deciding how long to wait can be tricky. If the question is very simple and slightly urgent, like "what's the deadline for this homework", or "is there a typo on this question of the problem sheet", then 24 hours is fine (not counting weekends and holidays). For slightly more demanding tasks, like "can I change classes", wait 2 to 3 working days. Bear in mind sometimes the person will have to forward your request to someone else, so they might also be awaiting a reply. If the request involves something very involved, like an application for a project, the reply is likely to take a couple of weeks, though your request will often be aknowledged upon receipt.
A common reason for a slow reply is the "can I do it in 30 seconds?" test. If a new message pings my inbox and I can reply to it in 30 seconds, I am likely to do so immediately. If I cannot, it goes onto the "I'll do it later" pile, and I might get to it eventually. Emails like the Montoya method examples above are guaranteed to get a quick reply; they're simple and clear, short and sweet. Of course, not every request is a 30 second request, but the point stands: try not to make your email more complicated than it needs to be.
On the opposite end of the spectrum is the problem of missing information. Sometimes, an email doesn't tell me everything I need to know. A classic example: you're a student inquiring about a summer project. In your first email, you should include relevant information like your name, year of study, degree, university, subjects you have taken, relevant skills, etc. A good strategy is to attach a CV with all the information, and only highlight the most relevant points on the email. If some of this information is missing, my first reply will be to ask for clarification, which just delays the whole process.
This email reaches me often in October, when final year / master's students are choosing a dissertation topic. To discuss what, may I ask? As a rule, I don't agree to meetings before knowing what the meeting is about. This is because there are only so many hours in the day, and because many meetings could have been an email instead. If the question is straightforward, like "how much programming experience do I need for this topic", I can quickly answer that via email (to you, and the other 10 people who will likely have same question). If the question requires more discussion, then yes, we should arrange a meeting, but I won't agree to meet until I know what the question is. Sorry.
In short, if you want answers to your questions, you should write them clearly on the first email.
The greeting. Do you write "Dear Rafael" or "Dear Dr Bailo"? Personally, I don't mind. Some people don't care, and some prefer one over the other. The best strategy when you email someone new is to begin addressing them as "Dr Surname", and to look out for their reply: they might sign their email as "Dr Surname", or as "Firstname", and you can address them like that in the replies.
Dr or Prof.? The style varies from country to country. In the UK, Professor is an actual job title, so Lecturers, Readers, Researchers, and other members of staff will usually be addressed as Doctor. However, in some countries, anyone teaching at a University is addressed as Professor. If in doubt, it's better to promote than to demote!
Note: abbreviations which include the first and last letters of a word are written without a period. So we write "Mr Surname", "Ms Surname", "Mrs Surname", and "Dr Surname", but "Prof. Surname".