I noticed in outlook express that there is a macros function and so I want to play with it! Unfortanetly, I have not programmed in VB for about 5 years.
I get a lot of mailer daemons from clients and employees to my email system which someone has to go through and update our MySQL database to void the email manually.
So, I want to know if it is possible to take the emails from the mail开发者_如何学Cer daemons and simply update a MySQL database with a macros? Resources or examples please?
I'm sure it is simple but my google searches come back with little help.
Here are some rough notes.
Dim cn As Object
Dim sCon As String
Dim sSQL As String
Dim oNameSpace As Outlook.NameSpace
Dim oItem As Outlook.MailItem
Dim oFolder As Outlook.MAPIFolder
Set cn = CreateObject("ADODB.Connection")
sCon = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=MyDB;" _
& "User=UName;Password=PWord;Option=3;"
cn.Open sCon
Set oNameSpace = Application.GetNamespace("MAPI")
Set oFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
For Each oItem In oFolder.Items
If Left(oItem.Sender, 13) = "MAILER-DAEMON" Then
sSQL = "INSERT INTO TestTable (data) VALUES ('" & oItem.Sender & "')"
cn.Execute sSQL
End If
Next
See also: http://www.outlookcode.com/article.aspx?id=62
http://www.connectionstrings.com/mysql
These tutorial/post here explain well how to event handle (first link for Mail event; second link for Calendar event):
https://www.slipstick.com/developer/itemadd-macro/
VBA how to event handle ItemAdd & ItemChange both (for Outlook 2016 Calendar)?
and this post here explains well how to use VBA to connect with MySQL :
https://www.mrexcel.com/board/threads/how-vba-connect-mysql-database-and-run-a-simple-query.1054774/
Combine the above, with minor modifications you should be able to achieve what you wanted.
Make sure you have the ODBC driver whose download link is as Fionnuala supplied.
精彩评论