Summary of the invention
The technical problem to be solved by the invention is to provide a kind of automatic method and system for sending Email, are used for
Realize the automatic transmission of Email.
In order to solve the above technical problems, the present invention provides a kind of automatic methods for sending Email, comprising steps of
S1, the extraneous hair mail requests sent are received;The hair mail requests include mail element, the mail element packet
Include mail matter topics, message body, mail sender, mail recipient's list;
After s2, the hair mail requests described in receiving, pre-set stmp client connection is called to be arranged in advance automatically
Mail server sends current mail, if mail is sent successfully then executes step s5, otherwise continues to execute step s3;
S3, check whether the mail server enables the dynamic adjustment of the configuration of stmp agreement, if inspection result is to enable
The dynamic adjustment of the configuration of stmp agreement, then detect the mail server that the connection of stmp client is arranged in advance in step s2
Protocol interaction, and according to probe result and the corresponding configuration for adjusting the stmp client of pre-set configuration strategy, so
It calls the stmp client to retransmit when previous mail again afterwards, if this mail is sent successfully, then executes step
Otherwise rapid s5 then continues to execute step s4;
S4, call pre-set local outlook mailbox client to retransmit current mail again, if this transmission at
Function then continues to execute step s5, otherwise then executes step s6;
S5, current mail transmission terminate, and be current mail mark its transmission result be to send successfully;
S6, current mail transmission terminate, and be current mail mark its send result be send fail.
Wherein, in step s3, the stmp client in step s2 of detecting connects the mail server being arranged in advance
Protocol interaction, authorization type, encryption type and port numbers including the mail server.
Wherein, which is realized based on Java language, wherein the stmp client is adopted
With the library javaMail, the outlook mailbox client is based on com component automatic technology and is controlled.
Wherein, the mail element further includes mail CC list.
In addition, the present invention also provides a kind of automatic systems for sending Email, comprising:
Stmp client;
Outlook mailbox client;
Mail requests receiving unit, for receiving the extraneous hair mail requests sent;The hair mail requests include that mail is wanted
Element, the mail element include mail matter topics, message body, mail sender, mail recipient's list;
First processing units are connected with the mail requests receiving unit and stmp client respectively, described in receiving
After sending out mail requests, the mail server for calling pre-set stmp client connection to be arranged in advance automatically sends current postal
Part;
The second processing unit is connected with the first processing units, presets for calling automatically in first processing units
The mail server that is arranged in advance of stmp client connection send current mail failure after, whether check the mail server
The dynamic adjustment of the configuration of stmp agreement is enabled, if testing result is the dynamic adjustment for the configuration for enabling stmp agreement,
The protocol interaction for the mail server that the connection of stmp client described in first processing units is arranged in advance is detected, and foundation is detected
As a result and pre-set configuration strategy corresponds to the configuration for adjusting the stmp client, then calls the stmp again
Client retransmits current mail;
Third processing unit is connected with described the second processing unit and outlook mailbox client respectively, at second
After reason cell call stmp client sends mail failure again, the outlook mailbox client is called to send out again again
Send current mail;
Fourth processing unit is connected with the first processing units, the second processing unit and third processing unit respectively, is used for
The mail server that first processing units call pre-set stmp client connection to be arranged in advance automatically sends current mail
When success, when the second processing unit calls stmp client to send current mail success again and in third processing unit
When the outlook mailbox client being called to retransmit current mail success again, it is respectively used to as current mail label
It is to send successfully that it, which sends result,;It is also used to call the outlook mailbox client again again in third processing unit
Send current mail failure when, be current mail mark its send result be send fail.
Wherein, the mail clothes that the connection of stmp client described in the first processing units that second unit detects is arranged in advance
The protocol interaction of business device, authorization type, encryption type and port numbers including the mail server.
Wherein, which is realized based on Java language, wherein the stmp client is adopted
With the library javaMail, the outlook mailbox client is based on com component automatic technology and is controlled.
Wherein, mail element described in mail requests receiving unit further includes mail CC list.
Compared with the prior art, the advantages of the present invention are as follows:
(1) method of automatic transmission Email of the present invention, based on the hair mail requests that the external world received is sent,
The mail server for first calling pre-set stmp client connection to be arranged in advance sends current mail, loses if mail is sent
It loses, whether re-inspection mail server enables the dynamic adjustment of the configuration of stmp agreement, and is to enable in inspection result
After the dynamic adjustment of the configuration of stmp agreement, the protocol interaction for the mail server that the connection of stmp client is arranged in advance is detected,
And the configuration of the stmp agreement of corresponding adjustment stmp client, then call the stmp client to retransmit again current
Secondary mail recalls local outlook mailbox client and retransmits mail again if this mail is still transmission failure,
It can be seen that the present invention is not only able to achieve the automatic transmission of Email, but also it can not only send stmp mail, can also send
Outlook mail, it is seen that the present invention can be suitable for a variety of transmission scenes, more practical.
(2) system of automatic transmission Email of the present invention, the side with the automatic transmission Email
Method is corresponding, and all advantages of the method with the automatic transmission Email are not repeating herein.
It can be seen that compared with prior art, the present invention implementing with substantive distinguishing features outstanding and significant progress
Beneficial effect be also obvious.
Specific embodiment
To keep technical solution of the present invention and advantage clearer, below in conjunction with attached drawing, to technical solution of the present invention
It is clearly and completely described.
Fig. 1 is a kind of specific embodiment of the method for automatic transmission Email of the present invention.In present embodiment
In, this sends the method for Email automatically, includes the following steps s1-s6, for realizing the automatic transmission of Email.
S1, the extraneous hair mail requests sent are received.
Wherein, the hair mail requests include mail element, the mail element include mail matter topics, mail just
Text, mail sender, mail recipient's list and mail CC list.
Wherein, in the present embodiment, each " external world " involved in the present invention, refer to using of the present invention
The application system of the automatic method for sending Email, when specifically used, the application system is periodically or mail described in timing acquiring
The corresponding each content of element simultaneously automatically initiates hair mail requests.
After s2, the hair mail requests described in receiving, pre-set stmp client connection is called to match in advance automatically
If mail server send current mail, if mail is sent successfully transfer execution step s5, otherwise continue to execute step s3.
Wherein, Stmp client is directly interacted with mail server, and mail server is first center for depositing mail
Address, stmp client send mail dependent on mail server.Mail on mail server is labeled with mail receipts
Mail can be carried out forwarding appropriate using the information of mail recipient by part people's information, mail server.
Wherein, stmp client before the use, needs to be arranged its corresponding mail server, the content packet of setting in advance
Include address and the port numbers of mail server.
In the present embodiment, which is realized based on Java language, wherein described
Stmp client uses the library javaMail.
S3, check whether the mail server enables the dynamic adjustment of the configuration of stmp agreement, if inspection result is
The dynamic adjustment for enabling the configuration of stmp agreement then detects stmp client in step s2 and connects the mail service being arranged in advance
The protocol interaction of device, and corresponded to according to probe result and pre-set configuration strategy and adjust matching for the stmp client
It sets, then calls the stmp client to retransmit when previous mail again, if this mail is sent successfully, then hold
Otherwise row step s5 then continues to execute step s4.
Wherein, there are three kinds of following (1)-(3) situations for the configuration strategy of the stmp client based on the library javamail:
(1) basic connection is configured with user name, password, coding mode etc..
Mail.stmp.user=your_name
Mail.stmp.password=your_password
defaultEncoding=utf-8
Mail.stmp.auth=true
(2) if mail server has used the domain window authentication mode, ntmp is needed to configure, and username and password will be changed to
The username and password used when the login of windows the machine.
Mail.stmp.user=your_computer_name
Mail.stmp.password=your_computer_password
Mail.stmp.auth=ntmp
(3) mail server having can configure cipher mode, have two kinds of cipher modes of ssl and starttls, add when being configured to ssl
When close mode, the configuration parameter that needs are as follows:
mail.stmp.socketfactory.class=javax.net.ssl.SSLSockeFactory;
mail.stmp.socketfactory.fackback=true;
mail.stmp.socketfactory.port=465;
mail.stmp.port=465.
If mail server configuration is startttls cipher mode, increased be configured that is needed
Mail.starttls.enable=true
Mail.stmp.port=587
So far as it can be seen that the configuration based on mail server, selects corresponding configuration parameter as the configuration parameter of stmp client.
In step s3, the agreement for detecting the mail server that the connection of stmp client is arranged in advance in step s2
Interaction, authorization type, encryption type and port numbers including the mail server.
Further, the present invention can also analyze stmp client by way of program debug by telnet tool
The protocol interaction for the mail server that end connection is arranged in advance, detects out the configuration parameter of mail server, including mail service
Authorization type, encryption type and the port numbers of device.
For example, the interactive process that stmp protocol interaction starts has indicated that rough configuration mode, it is as follows:
EHLO server_host
250-xxx.server_host Hello [xxx.xx.xx.x]
250-SIZE 52469760
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-X-ANONYMOUSTLS
250-AUTH GSSAPI NTLM
250-X-EXPS GSSAPI NTLM
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250-XEXCH50
250-XRDST
250 XSHADOW
This time interaction is shown, and stmp client needs to be logged in the domain windows authentication mode, and needs to be added with starttls
Close mode.
S4, pre-set local outlook mailbox client is called to retransmit current mail again, if this sends
Success, then continue to execute step s5, otherwise then executes step s6.
The outlook mailbox client is based on com component automatic technology and is controlled.
Wherein, the mode that Com component automation mode completes mail needs a few step preparations, firstly, in windows sheet
Corresponding configuration is completed on machine, and outlook mailbox is enable normally to send mail;Then it obtains jacob.jar packet and corresponds to
Jacob.dll, and jacob.jar is put into class.path, is put into jaob.dll under the bin catalogue of jre.So far,
The java code of the transmission outlook mail based on Variant and Dispatch interface is write in windows the machine.
Wherein, Jacob.dll is the realization of window com component automated server, and jacob.jar packet passes through jni skill
Art calls the interface in jacob.dll.Jacob.jar can manipulate all com components, including outlook mailbox client.
S5, current mail transmission terminate, and be current mail mark its transmission result be to send successfully.
S6, current mail transmission terminate, and be current mail mark its send result be send fail.
To sum up, the method for automatic transmission Email of the present invention, the hair postal sent based on the external world received
Part request, the mail server for first calling pre-set stmp client connection to be arranged in advance sends current mail, if mail
Failure is sent, whether re-inspection mail server enables the dynamic adjustment of the configuration of stmp agreement, and is to open in inspection result
After dynamic adjustment with the configuration of stmp agreement, the agreement for detecting the mail server that the connection of stmp client is arranged in advance is handed over
Mutually, and the configuration for adjusting the stmp agreement of stmp client is corresponded to, the stmp client is then called to retransmit again
When previous mail, if this mail is still transmission failure, recalls local outlook mailbox client and retransmit postal again
Part, it is seen that the present invention is not only able to achieve the automatic transmission of Email, but also it can not only send stmp mail, can also send
Outlook mail, it is seen that the present invention can be suitable for a variety of transmission scenes, more practical.
In addition, referring to fig. 2, the present invention also provides a kind of automatic system for sending Email, the system and it is above-mentioned from
The dynamic method for sending Email is corresponding, comprising:
Stmp client;
Outlook mailbox client;
Mail requests receiving unit, for receiving the extraneous hair mail requests sent;The hair mail requests include that mail is wanted
Element, the mail element include mail matter topics, message body, mail sender, mail recipient's list and mail CC people
List;
First processing units are connected with the mail requests receiving unit and stmp client respectively, described in receiving
After sending out mail requests, the automatic mail server for calling the stmp client connection to be arranged in advance sends current mail;
The second processing unit is connected with the first processing units, described for calling automatically in first processing units
After the mail server that the connection of stmp client is arranged in advance sends current mail failure, check whether the mail server opens
It is visited with the dynamic adjustment of the configuration of stmp agreement if testing result is the dynamic adjustment for the configuration for enabling stmp agreement
The protocol interaction for the mail server that the connection of stmp client described in first processing units is arranged in advance is looked into, and foundation detects knot
Fruit and the corresponding configuration for adjusting the stmp client of pre-set configuration strategy, then call the stmp visitor again
Family end retransmits current mail;
Third processing unit is connected with described the second processing unit and outlook mailbox client respectively, at second
After reason cell call stmp client sends mail failure again, the outlook mailbox client is called to send out again again
Send current mail;
Fourth processing unit is connected with the first processing units, the second processing unit and third processing unit respectively, is used for
First processing units call the stmp client to connect the mail server being arranged in advance automatically and send current mail success
When, the second processing unit call stmp client send again current mail success when and third processing unit call
When the outlook mailbox client retransmits current mail success again, it is respectively used to mark its hair for current mail
Sending result is to send successfully;It is also used to call the outlook mailbox client to retransmit again in third processing unit
Current mail fail when, be current mail mark its send result be send fail.
Wherein, in the present embodiment, each " external world " involved in the present invention, refer to using of the present invention
The application system of the automatic method for sending Email, when specifically used, the application system is periodically or mail described in timing acquiring
The corresponding each content of element simultaneously automatically initiates hair mail requests.
Wherein, Stmp client is directly interacted with mail server, and mail server is first center for depositing mail
Address, stmp client send mail dependent on mail server.Mail on mail server is labeled with mail receipts
Mail can be carried out forwarding appropriate using the information of mail recipient by part people's information, mail server.
Wherein, stmp client before the use, needs to be arranged its corresponding mail server, the content packet of setting in advance
Include address and the port numbers of mail server.The mail server being arranged in advance is to match in advance in the stmp client
If mail server.
Wherein, second unit detects the first processing list telnet tool (by way of can also be by program debug)
The protocol interaction for the mail server that the connection of stmp client described in member is arranged in advance, probe result include the mail service
Authorization type, encryption type and the port numbers of device.
Wherein, which is realized based on Java language, wherein the stmp client is adopted
With the library javaMail.
Wherein, the configuration strategy of the stmp client based on the library javamail, referring to above-mentioned automatic transmission Email
Three kinds of (1)-(3) situation in the embodiment of method, details are not described herein.
In the present embodiment, the outlook mailbox client is controlled based on com component automatic technology.
Wherein, the mode that Com component automation mode completes mail needs a few step preparations, firstly, in windows sheet
Corresponding configuration is completed on machine, and outlook mailbox is enable normally to send mail;Then it obtains jacob.jar packet and corresponds to
Jacob.dll, and jacob.jar is put into class.path, is put into jaob.dll under the bin catalogue of jre.So far,
The java code of the transmission outlook mail based on Variant and Dispatch interface is write in windows the machine.
Wherein, Jacob.dll is the realization of window com component automated server, and jacob.jar packet passes through jni skill
Art calls the interface in jacob.dll.Jacob.jar can manipulate all com components, including outlook mailbox client.
To sum up, the system of automatic transmission Email of the present invention when in use, passes through mail requests receiving unit
The extraneous hair mail requests sent are received, the hair mail that mail requests receiving unit is sent is received by first processing units and asks
It asks, and after receiving the hair mail requests, first processing units call the stmp client to connect automatically (should
In stmp client) mail server that is arranged in advance sends current mail;Later by the second processing unit, in the first processing
After unit calls the stmp client to connect the mail server transmission current mail failure being arranged in advance automatically, institute is checked
The dynamic adjustment whether mail server enables the configuration of stmp agreement is stated, if testing result is to enable matching for stmp agreement
The dynamic adjustment set, then detect the agreement for the mail server that the connection of stmp client described in first processing units is arranged in advance
Interaction, and according to probe result and the corresponding configuration for adjusting the stmp client of pre-set configuration strategy, then again
Stmp client described in secondary calling retransmits current mail;Later by third processing unit, in the second processing unit tune
After sending mail failure again with stmp client, pre-set local outlook mailbox client is called to send out again again
Send current mail.Wherein, the stmp client is called to connect the mail service being arranged in advance automatically in first processing units
When device sends current mail success, the stmp client is called to send current mail success again in the second processing unit
When, and when third processing unit calls the outlook mailbox client to retransmit current mail success again, point
Not by fourth processing unit be current mail mark its send result be to send successfully.In addition, being called in third processing unit
It is current mail by fourth processing unit when the outlook mailbox client retransmits current mail failure again
It is marked to send result to send failure.
As it can be seen that the present invention is not only able to achieve the automatic transmission of Email, but also stmp mail can be sent but also sent
Outlook mail, it is seen that it is suitable for a variety of transmission scenes and uses, it is more practical.
Embodiment of above is merely illustrative of the technical solution of the present invention, rather than its limitations;Although referring to aforementioned implementation
Invention is explained in detail for mode, those skilled in the art should understand that: it still can be to aforementioned each
Technical solution documented by embodiment is modified or equivalent replacement of some of the technical features;And these are repaired
Change or replaces, the range for each embodiment technical solution of the present invention that it does not separate the essence of the corresponding technical solution.