Summary of the invention
The invention provides a kind of e-mail sending method and device, at least to solve in correlation technique workload and the maintenance cost problem that the code redundancy that sends personalized mail and cause is high, increase the developer.
According to an aspect of the present invention, provide a kind of e-mail sending method, it comprises: loading configuration file, and wherein, configuration file comprises: template engine; Adopt template engine to call the mail template that mail to be sent is corresponding; Use the mail template generate mail to be sent and send.
Preferably, adopting before template engine calls the mail template that mail to be sent is corresponding, above-mentioned e-mail sending method also comprises: the mail template that the interval predetermined period more sets in advance in new database.
Preferably, adopting template engine to call the mail template corresponding with mail to be sent comprises: adopt template engine to call the mail template corresponding with mail to be sent from the mail template set in advance.
Preferably, using the mail template to generate mail to be sent and send comprises: by configuration file, for the information that sends mail to be sent, being filled up to the mail template, generating mail to be sent and send.
Preferably, using the mail template to generate mail to be sent and send comprises: select the send mode be complementary with email type to be sent to send mail to be sent.
Preferably, send mode comprises: send the mode of the mail of the mode of template mail, the mode that sends text-mail, transmission webpage format, the mode that transmission includes the webpage format mail of picture or annex.
Preferably, before loading configuration file, above-mentioned e-mail sending method also comprises: send mode is detected, determine that send mode is normal.
According to a further aspect in the invention, provide a kind of mail dispensing device, it comprises: load-on module, and for loading configuration file, wherein, configuration file comprises; Template engine; Calling module, call for adopting template engine the mail template that mail to be sent is corresponding; Sending module, generate mail to be sent and send for using the mail template.
Preferably, above-mentioned mail dispensing device also comprises: update module, and for the interval predetermined period mail template that more new database sets in advance.
Preferably, above-mentioned mail dispensing device also comprises: detection module, for the mode to sending mail to be sent, detected, and determine that send mode is normal.
In the present invention, pass through loading configuration file, load template engine, and adjust and the mail template corresponding with mail to be sent by this template engine, then, use above-mentioned mail template to generate mail to be sent, and mail to be sent is sent, realized can be different according to the user demand call different mail templates by template engine, to generate different mails, when meeting the multiple demand of user, use due to template engine, the problem that all needs exploitation code while having avoided the mail of each transmission different-style, thereby reduced code redundancy, reduced developer's workload, reduced maintenance cost.
Embodiment
Hereinafter with reference to accompanying drawing, also describe the present invention in detail in conjunction with the embodiments.It should be noted that, in the situation that do not conflict, embodiment and the feature in embodiment in the application can combine mutually.
In the present embodiment, provide a kind of e-mail sending method, as shown in Figure 1, this e-mail sending method comprises that step S102 is to step S106.
Step S102: loading configuration file, wherein, configuration file comprises: template engine.
Step S104: adopt template engine to call the mail template that mail to be sent is corresponding.
Step S106: use the mail template generate mail to be sent and send.
Pass through above-mentioned steps, at first loading configuration file, load template engine, and adjust and the mail template corresponding with mail to be sent by this template engine, then, use above-mentioned mail template to generate mail to be sent, and mail to be sent is sent, realized can be different according to the user demand call different mail templates by template engine, to generate different mails, when meeting the multiple demand of user, use due to template engine, the problem that all needs exploitation code while having avoided the mail of each transmission different-style, thereby reduced code redundancy, reduced developer's workload, reduced maintenance cost.
Preferably, above-mentioned e-mail sending method can realize in the following manner, based on spring+velocity+javamail, realize, wherein, Spring Framework is the application framework of a Java/Java EE global function stack (full-stack) of increasing income, with the issue of Apache licence form, the transplanting version on the .NET platform is also arranged.This framework is based on Expert One-on-One Java EE Design and Development(ISBN 0-7645-4385-7) code in a book, at first by exploitations such as Rod Johnson and Juergen Hoeller.Spring Framework provides an easy development scheme, and this development scheme, by a large amount of property files and help class of avoiding those may cause bottom code to become numerous and diverse confusion.
Velocity is a template engine (template engine) based on java.It allows anyone only simply to use template instruction (template language) to quote the object by the java code definition.When Velocity is applied to the web exploitation, the interface personnel can synchronously develop a web website of following the MVC framework with java program development personnel, that is to say, the Pages Design personnel can only pay close attention to the display effect of the page, and pay close attention to the service logic coding by java program development personnel.Velocity separates the java code from web page, for the long-time maintenance of web website, provides convenience like this, and a kind of optional scheme also is provided again outside JSP and PHP for us simultaneously.
The exploitation of Java Mail API is that SUN provides public API framework for Java developer.The simple tool that this API can yet be regarded as and adds healthy and strong mail/communication to support in application program.
By the way, can use spring+velocity+javamail to realize loading different templates, realize the transmission of personalized mail, when meeting consumers' demand fast, can reduce code redundancy.
Meet the demand of different user in order to obtain in real time various mail template, in this preferred embodiment, adopting before template engine calls the mail template that mail to be sent is corresponding the mail template that the interval predetermined period more sets in advance in new database.Can the predetermined period of different length be set according to the needs that upgrade, realization can be upgraded the template in template base in real time, so that the mail template that quick obtaining needs; In addition, without restarting server, just can be loaded into different mail templates, be convenient to expansion, improve the dirigibility of system.
The step that above-mentioned employing template engine calls the mail template corresponding with mail to be sent comprises: adopt template engine to call the mail template corresponding with mail to be sent from the mail template set in advance.By calling the mail template corresponding with mail to be sent the mail template from setting in advance, can meet rapidly different user and send personalized mail demand, for example, the template of calling can be following form:
$ username}, you are good, Custom House Welcome to Custom House<A href=$ url}target=_blank > ZTE Corporation</A >!
Sender's e-mail messages mail.properties
Main contents are as follows:
mail.host=smtp.gmail.com
mail.port=25
mail.username=yourname
mail.password=yourpassword
mail.smtp.auth=true
mail.smtp.timeout=25000
mail.default.from=yourname@gmail.com
Realize the transmission of mail, in this preferred embodiment, use the mail template to generate mail to be sent and send and comprise: by configuration file, for the information that sends mail to be sent, being filled up to the mail template, generating mail to be sent and send.Be about in configuration file for the information that sends mail to be sent (for example, load property file (propertyConfigurer), load mailbox server parameter information (mailSender), load the information such as mail sender's parameter information (simpleMailMessage)) be filled up to generation mail to be sent in the mail template, exactly mail to be sent is sent.
For the ease of the transmission of different mail, in this preferred embodiment, use the mail template to generate mail to be sent and send and comprise: select the send mode be complementary with email type to be sent to send mail to be sent.Can adopt different send modes for different mails, for example, this send mode can comprise: send the mode of the mail of the mode of template mail, the mode that sends text-mail, transmission webpage format, the mode that transmission includes the webpage format mail of picture or annex.
Transmission success in order to ensure mail, improve the success ratio that sends mail, in this preferred embodiment, before loading configuration file, send mode detected, and determines that send mode is normal.For example, call the sendXXX () wanted after setting parameter, test and send the mail parameter.
In this preferred embodiment, a kind of preferred mail dispensing device is provided, as shown in Figure 2, this mail dispensing device comprises: load-on module 202, for loading configuration file, wherein, configuration file comprises: template engine; Calling module 204, be connected to load-on module 202, for adopting template engine, calls the mail template that mail to be sent is corresponding; Sending module 206, be connected to calling module 204, for using the mail template, generates mail to be sent and send.
In above preferred embodiment, by load-on module 202 loading configuration file, load template engine, calling module 204 is adjusted and the mail template corresponding with mail to be sent by template engine, then, sending module 206 is used above-mentioned mail template to generate mail to be sent, and mail to be sent is sent, realized can be different according to the user demand call different mail templates by template engine, to generate different mails, when meeting the multiple demand of user, use due to template engine, the problem that all needs exploitation code while having avoided the mail of each transmission different-style, thereby reduced code redundancy, reduced developer's workload, reduced maintenance cost.
Meet the demand of different user in order to obtain in real time various mail template, in this preferred embodiment, as shown in Figure 3, above-mentioned mail dispensing device also comprises: update module 208, and for the interval predetermined period mail template that more new database sets in advance.
Transmission success in order to ensure mail, improve the success ratio that sends mail, in this preferred embodiment, as shown in Figure 4, above-mentioned mail dispensing device also comprises: detection module 210, for the mode to sending mail to be sent, detected, and determine that send mode is normal.
Below in conjunction with accompanying drawing, above-mentioned each preferred embodiment is described in detail.
Fig. 5 is the transmission according to the embodiment of the present invention, the schematic diagram of reception mail, as shown in Figure 5, sends the environment schematic diagram of mail, and operator carries out the mail transmission by the intenet network, and domestic consumer receives mail by the intenet network and carries out the mail reading.Under internet commercial websites application scenarios, by the configuration of the difference to the template resource, reach and do not increasing under the prerequisite of revising the java code, for different client crowds, load different templates, realize sending personalized mail, for example, send the template mail, send the plain text mail, send the webpage format mail, send the webpage format mail that comprises picture, send the personalized mails such as webpage format mail that comprise annex.The implementation method of above-mentioned transmission mail, code structure is clear, and project development is complete, after deployment is reached the standard grade, follow-up without developer's intervention, the user only need to revise the template resource, just can send different e-mail messages according to service needed, reach and attract the user, improve the purpose of enterprise's self-image.Improve user's reading mail and experience, improved user's reading mail quality.Under the overall situation of Internet industry, expand the business of oneself for operator, improved feasible method.
Fig. 6 sends the schematic diagram of mail method according to the another kind of the embodiment of the present invention, as shown in Figure 6, operator loads into different mail templates according to business demand, then, mail is put into to transmit queue, by the internet network, sent, the mailbox of domestic consumer can be received the mail of operator by the internet network, domestic consumer opens the mailbox of oneself just can read the mail of the various personalizations of operator's transmission, improve user's reading mail and experience, improved user's reading mail quality.Above-mentioned transmission mail method comprises the steps:
Step 1: send mail service module (MailSenderService) (being equivalent to above-mentioned load-on module 202) loading configuration file.
Step 2: periodic refreshing mail formwork module (being equivalent to above-mentioned update module 208), carry out the scanning of mail template.
Step 3: send mail service module (MailSenderService) and load mail template (i.e. the mail template corresponding with mail to be sent).
Step 4: transmission mail service module (MailSenderService) is assembled (generating mail to be sent) by personalized mail and is put into mail queue.
Step 5: operator calls and sends mail service module (MailSenderService), by the internet network, personalized mail in mail queue is sent
Step 6: send mail, flow process finishes.
Step 7: personalized mail, by the internet network, enters domestic consumer's mailbox
Step 8: domestic consumer opens individual mailbox, the Personality of reading mail.
Step 9: receive mail, flow process finishes.
From above description, can find out, the present invention has realized following technique effect: pass through loading configuration file, load template engine, and adjust and the mail template corresponding with mail to be sent by this template engine, then, use above-mentioned mail template to generate mail to be sent, and mail to be sent is sent, realized can be different according to the user demand call different mail templates by template engine, to generate different mails, when meeting the multiple demand of user, use due to template engine, the problem that all needs exploitation code while having avoided the mail of each transmission different-style, thereby reduced code redundancy, reduced developer's workload, reduced maintenance cost.In addition, the interval predetermined period is to upgrading the template in template base, the mail template that quick obtaining needs; In addition, without restarting server, just can be loaded into different mail templates, be convenient to expansion, improve the dirigibility of system.
Obviously, those skilled in the art should be understood that, above-mentioned each module of the present invention or each step can realize with general calculation element, they can concentrate on single calculation element, perhaps be distributed on the network that a plurality of calculation elements form, alternatively, they can be realized with the executable program code of calculation element, thereby, they can be stored in memory storage and be carried out by calculation element, and in some cases, can carry out step shown or that describe with the order be different from herein, perhaps they are made into respectively to each integrated circuit modules, perhaps a plurality of modules in them or step being made into to the single integrated circuit module realizes.Like this, the present invention is not restricted to any specific hardware and software combination.
The foregoing is only the preferred embodiments of the present invention, be not limited to the present invention, for a person skilled in the art, the present invention can have various modifications and variations.Within the spirit and principles in the present invention all, any modification of doing, be equal to replacement, improvement etc., within all should being included in protection scope of the present invention.