Hunter Mail

Tuesday, May 25, 2010 8:00:00 PM Categories: Access e-mail Hunter
Rate this Content 1 Votes

One of the applications we use a lot from now on in several modules of the Hunter is sending e-mails. Whether to send the result of an analysis, a periodic report, a check of parameters, or any other purpose, sending automated e-mail saves us considerable time in formatting, minimizes errors, among other advantages that we will soon.

 

 

So, let's take a break location based on modules, which mainly use Mapinfo and Google Earth, and return to work a little harder with Access and VBA - although sending e- mails can be performed by any application that has the programming language. Let's see how to do this in a simple and professional.

Note: All telecomHall articles are originally written in Portuguese. Following we translate to English and Spanish. As our time is short, maybe you find some typos (sometimes we just use the automatic translator, with only a final and 'quick' review). We apologize and we have an understanding of our effort. If you want to contribute translating / correcting of these languages, or even creating and publishing your tutorials, please contact us: contact.

 

Purpose

Learn to send emails automatically with the module information Tool Hunter.

The Hunter Mail module actually works as an assistant to the results of other modules Hunter. According to the characteristics of each module an email is composed and sent to a predefined list of contacts. We can send one or more attached files, graphics and also the body of the email. However, to date we have not seen how to create formatted reports or graphs, so we'll use the data available so far - a file with data records of our network. Other features with a more advanced will be seen in due course, when the time is. Today we learn how the process is standard.

Even e-mails weekly for members and also to Subscribers are automatically sent to a process similar to what we see today.

Note: Almost all tutorials have related files, which are sent to Subscribers.

  • If you are a Subscriber, please check the received file for this tutorial in your email, and use the support for any questions or problems you find.
    • Blog_011_Hunter_Mail.zip.
  • If you are a Member and has access only to the written tutorial, you can still learn very important concepts that will surely help you in your own developments. Read and check on each new tutorial.
    • If you wish to contribute in some way, the simplest way is to become a Subscriber.

Our audience is from students to experienced professionals. Therefore we ask for a little understanding and tolerance if some some of the concepts presented today are too basic for you. Moreover, all the tutorials, codes and programs are at a continuous process of editing. This means that if we find any error, for example, grammar or spelling, try to fix it as soon as possible. We would also like to receive your feedback, informing us of errors or passages that were confusing and deserve to be rewritten.

 

File Structure

As usual, we must create a structure to contain the files that module.

Hunter In the root directory, create the directory Mail (1). Just below the Mail directory, create the Scripts directory (2).

 

In simple it is. Other directories will be created when needed.

 

What is an E-mail

Before anything, you know what is the definition of an e-mail, and how is it sent? It seems obvious, and our goal is not to detail this, but it is worthwhile to understand some basic concepts.

Note: we are sure that you have used email before. Anyway, it's worth taking a quick set in concepts.

An email is basically the transmission of a digital message through an electronic medium like the Internet. But thus setting is very generic, and seems to complex, since that message transmission can be anything. So let's not complicated: an e-mail is as simple as a letter you write and send by traditional mail.

It is quite easy when we make an analogy with letters and snail mail. And to understand this analogy, let's see what the differences are.

 

  • message: instead of using a pen to write a letter on paper you use your computer keyboard and a program editor, e-mail.
  • shipping: When you finish creating your email you say to whom he will, or the addressee. Except that for the message to follow your journey, instead of putting a stamp you just sends the send button.
  • transport: well as carrying messages and mail packages, e-mail servers transmit messages from senders to recipients.
  • received: occurs when you have a new message in your inbox, and is notified - you then go and grip. Likewise, programs for checking e-mail if you have new message and warn you so you can download and read.

Okay, the e-mail can be explained as we did above, since the objectives and basic operation is the same: exchanging messages. But the e-mail can do things that traditional mail can not, and even perform tasks that both the electronics can do much better. That is why the e-mail has become so widespread, the vast amount of advantages.

The main advantages we can emphasize the convenience - send and receive email anytime, anywhere, of course depend on the availability of access to the program e-mail connectivity, the speed - which allows a message reaches its destination almost instantaneously, and availability of attachments - which allows you to attach files from your computer; accessibility - to be conveniently stored in the e-mail programs that are currently true personal organizers, integrating tasks do, etc.. And of course, costs: practically zero if you have Internet access.

 

But there are also problems. Unfortunately, the last mentioned benefit is also responsible for one of the biggest current problems - spam, or unsolicited e-mails that are sent in large numbers, usually with junk mail or computer viruses. With hundreds of junk emails in your inbox, sometimes good emails can go unnoticed. Today we have sophisticated programs that try to prevent these types of problems, but the battle still continues.

 

But as e-mail is sent

For an e-mail can be sent and received, it is necessary first of all a server sending and receiving emails. And when we talk about email servers, usually comes with a lot of acronyms - SMTP, POP3, IMAP, etc ... The majority refers to protocols that are used for processing or for sending and receiving of messages.

 

Come on, some more settings. Let's try to be brief.

  • SMTP (Simple Mail Transfer Protocol) is the international standard used to transfer mail between computers.
  • POP (Post Office Protocol) is one of the protocols used by readers e-mail (Eudora, Netscape, Outlook, etc.) to retrieve messages on the e-mail. Messages are transferred from server to local computer when the user connects to the server. After searching the messages the connection can be undone, proceed to the reading of messages without being connected to the server.
  • IMAP (Internet Message Access Protocol) is another standard protocol used by mail readers to access the messages that arrive in e-mail server. Unlike POP, IMAP using the connection between the local computer server and e-mail should always be active because there is a constant interplay between them. Messages are kept in the e-mail, but accessed as if they were locally.

Servers can use e-mail applications like e-mail client, those installed on your computer like Outlook or Eudora. But the e-mails can also be sent and/or received via Internet, as is the case of Yahoo Mail, Gmail, Hotmail, etc..

Well, enough theory. If you're interested in learning more about e-mails, we suggest you do a search on the Internet, or if you prefer to enlist the help of our support.

To send an e-mail automatically, necessarily need to have a client application. And as if I have a client application? The most obvious, and already answered the question, is if you use one. But if you do not use, do the following test: click on the link below and see what happens Click Here. If you have an application e-mail standard and not know it, it will start, and there you will discover what it is, although you will need to configure it. At the end of this tutorial, we give an example of how to configure your e-mail from Google (Gmail) in Outlook Express - an application of standard e-mail from Microsoft that comes installed with Windows.

Note: another way to check what your e-mail default is to access the Control Panel -> Internet Options -> Programs and see which program program is listed as e-mails.

When you click a link for e-mail (mailto:'') as the above is somehow executing a command - or instruction - of the type: 'submit a new e-mail to this address, and let me edit until you click the send button. "

And the code is more or less the same thing: run the command line with these instructions. Depending on the application (Access, Excel, etc ...) or used for programming (VBA, C, etc ...) the syntax varies. But in general, follow a pattern very similar to the command that Access uses VBA and we will see below. Let's see examples

 

Sending a simple e-mail (Staff SendMail_01)

The simplest way to send an email through VBA in Access is using the command SendObject, and writing arguments, or the required details for sending and recipient subject, etc.. In VBA, we have seen that whenever we run a command started with 'DoCmd.' Followed by the desired command.

 

For commands that have arguments - as the case of SendObject - after you type the first '(', appear the required options and options that you can type highlighted in yellow. Bold appears the first argument, as well as their options.

 

Note: The command is called SendObject, but you have the option not to send any object (constant acSendNoObject), so you can send an email with text only if you wish.

Continue typing the command suggested in obeying the yellow text, ie typing the comma, is the next bold argument, and so on for each option until the end.

Following is the full command, and a brief description of what each argument represents.

DoCmd.SendObject (ObjectType, ObjectName, outputformat, To, Cc, Bcc, Subject, MessageText, EditMessage, templateFiles)

  • ObjectType : the pattern of this argument is acSendNoObject, which means not sending any object, but you can send any Access object like a table or query, thus they should be chosen appropriate constant acSendDataAccessPage, acSendForm, acSendModule, acSendQuery, or acSendReport acSendTable (the latter for instance if you want to send an attached table.)
  • ObjectName : an optional string that is the valid name of the object - if you are sending one. If you leave these first two options empty Access sends the email without any object.
  • outputformat : optional.
  • To : an expression with optional text message recipients. The recipients must be separated by '' (or the list separator, according to what you set in Regional Options in Control Panel). If there are errors with the list separator, will give an error when the application of e-mail tries to send the message, and then you adjust. If this argument is empty, Access will ask what are the intended recipients.
  • Cc and Bcc : optional expressions of text, like what we saw for To, except that if they are empty, Access and ignores the corresponding fields the message remains empty.
  • Subject : An optional expression text contend the text you want to put in the subject line of your e-mail. If you leave this argument blank, the matter goes blank.
  • MessageText : An optional string expression containing the text you want included in the message body. If empty, the body will also empty.
  • EditMessage : optional argument. Use True (-1) to open the application of standard email, allowing you to edit the message before sending. Use (0) to send the message without editing. If you leave this argument blank, the default (True) is assumed.
  • templateFiles : to use an HTML file as template. Let's not talk about it today, we'll look at another time.
  • Well, nobody will be decorating it, and it's easier to do and understand by example. Below is a practical example:

 

That is, when it runs the function SendMail_01 will be sent an email to telecomhall@gmail.com with the subject 'Function SendMail_01' and with the text 'This and email was sent automatically by SendMail_01 Function 'in the body of the email. See how simple it is? (Enter F5 or F8 and check that the e-mail is sent).

 

Outlook Security

Depending on the application of e-mail you use, you may receive a dialog box informing you that some e-mail is trying to be sent automatically, and if you want to allow this e-mail is sent.

 

This is a security configuration (as shown for Outlook on the image above), and it can not be canceled. In the future we will see that some modules need Hunter email automatically, and then we'll see how to avoid this security lock.

Anyway, whatever the confirmation request, then click Allow. Below, the request from Outlook Express, with the submission.

 

Help

You can and should consult the help of this command, and all others who use it. Do this always, is very good practice! For this, the VBE, select the command and click F1. Help you find further examples of use.

 

Sending a simple e-mail (Staff SendMail_02)

Okay, as we have seen e-mail. But has more work than using the client send e-mail, what advantage has it

Of course we will not be entering the arguments and options of the email as we did above. The great advantage of the program is allowing us to use variables, ie, we can get all of our input data from various sources, and mount command in accordance with what we need.

For example, this function does the same thing before, but now uses variables.

 

In this particular example, the variable values are assigned directly, but in future we will see that we can assign the value of these variables with data from several sources, such as tables, Excel files, text files , Images, etc..

In addition, we may use HTML in variable that contains the text of the message, then our limit is our creativity

Do not worry, whenever a module used for sending e-mail, you receive the full code that already does everything, including riding the HTML or other more advanced functionality. But it is very important that you go along and understand each new tutorial. No accumulation, otherwise you will not mind.

 

Sending an e-mail via Outlook using VBA (Staff SendMail_03)

Another way to send email via VBA application itself is using the e-mail (referencing the same). Thus, we create an object in memory containing the application. Then we create an object of this application - if an object email. Finally, configure the properties of that object e-mail with the information you want to send.

 

Note that the arguments are much the same.

This role specifically Network.xls also send the file, located in the C:\Hunter\Network\Data\ as attached file. For this we use the argument Attachments.Add followed by the name of the file you wish to attach.

 

Reference

Remember that when we refer to another program, we need to include a reference library in the module, but an error occurs as shown below.

 

Thus, open the VBE, go to the Tools menu (1) -> References (2), and select Microsfot Outlook Object Library X, where X is the version Outlook you use.

 

Note: The file sent to a reference library 12, referring to Office 2007. If you use another version, remember to make this correction.

We could stay here in extending indefinitely, creating countless combinations of commands for sending e-mails, etc.. But this is not our goal. It is important today only that you understand how the process works. And we recommend that if you have any more interest in the subject, see the Internet Help or VBA.

 

Finally, and again: do not worry! You will always receive all the programs with full code and commented. If you have any special needs, we can help you. Our support is available to you.

 

Configuring an email from GMAIL in Outlook Express

If you do not use - or want to use - the Outlook, one option is to use Outlook Express, a simple version of e-mails software, and comes installed with Windows. Outlook Express (msimn.exe) is located in the C: \ Program Files \ Outlook Express.

Finally for today, I'll give a full example of how to set up a Gmail account in Outlook Express.

The first action to take is to activate the Pop To do this, log into your Gmail account, and click Settings (1) at the top right and then tab select the Forwarding and POP / IMAP (2).

 

Choose the desired setting - for all e-mails or e-mail that arrives from now on. In field 2, you have the option to keep a copy of messages on the Gmail server or you can choose to delete them. The field number 3 is Google's own instructions for you to configure your email client, eg Outlook or Eudora.

After enabling POP, remember to click the Save button! Okay, let's now configure your client.

First, start Outlook Express. If this is the first time that it starts, skip the next paragraph. Otherwise, click on Tools (1) -> Accounts ... (2), and then in the new window, choose Add (3) -> E-mail (4).

 

In this new window you must enter your name (1). This is the name that will appear to people who receive their e-mails. Click the Next button (2). In our case typed TelecomHall Portal, you must enter your name.

 

Now enter your e-mail that is being set (1) and click the Next button (2). In our case, we typed telecomhall@gmail.com, you must enter your e-mail.

 

We did the most important part, which is to inform that our POP and SMTP server. For the server, select POP3 (1). E-mail Output type pop.gmail.com (2) and E-mail Input type smtp.gmail.com (3). Click the Next button (4).

 

In the new window, enter your e-mail account from Google (1) and also your password (2), and click the Next button (3).

 

Your account has been set, but still not finished. To continue, click the Finish button (1), which just means that we put the account information successfully, but still not enough for your Outlook Express to send or receive messages.

 

Wee need to do some little more settings, with a more advanced, but not too complicated.

Go back Menu Tools -> Accounts as we did earlier. Now in the open window appears to account pop.gmail.com (1). Select this account and click Properties (2).

 

In the new window, give a more meaningful name to your account, such as GMAIL (1).

 

In Servers tab (1), check My server requires authentication (2).

 

Finally, select the Advanced tab to configure the ports to which your Outlook Express will communicate with the server. Enter 465 for SMTP (1) and 995 for POP3 (2) and select the options for SSL (3) and (4).

 

Ready. Click the OK button - or Apply and then the OK button. If you have no other email account configured in Outlook Express, this account (only) is already as default. Otherwise, you can put it as default - recommended and required if you use it in automated modules Hunter - through the right mouse button menu, clicking on the account, and choosing Set As Default.

 

Conclusion

In this tutorial we saw how easy is to send an email using MS Access.

We hope you've enjoyed. If you have any doubts, find the answers posting your comments in the blog or via our support via chat or email.

Till our next meeting, and remember: Your success is our success!