Dgassert
asked on
email using VB
I am trying to send an automated email using VB to notify me when a file size changes.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dgassert,
Here's the code I use to send an automated email in an app I am currently working on.
Place a MAPISession control on your form, call it MAPISession1.
Place a MAPIMessages control on the form and call it mail
Place the following code in a sub called send_mail()
strMailName = dtaEmail.Recordset.Fields( 0)
strEmailName = dtaEmail.Recordset.Fields( 1)
MAPISession1.LogonUI = False
MAPISession1.UserName = "MICROSOFT OUTLOOK"
MAPISession1.SignOn
mail.SessionID = MAPISession1.SessionID
mail.Compose
mail.RecipDisplayName = strMailName
mail.RecipAddress = strEmailName
mail.ResolveName
mail.MsgSubject = "File size changed!"
'Create the message
mail.MsgNoteText = strEmailMessage
mail.Send False
MAPISession1.SignOff
When your file size changes call send_mail
The strMailName and strEmailName are variables I set for the users email address and name because I send it to several people. I have a DB table that contains the names and addresses of the people I will send this to. I set my recordset equal to these fields. Field "0" is the user name and Field "1" is their email address.
I then will put the above code in a for/next loop moving through the recordset until I have sent all of the emails.
The strEmailMessage is the variable I set to hold the message text for the email.
The MAPISession1.UserName = "MICROSOFT OUTLOOK" assumes I am logged onto the network and calls OUTLOOK with my account info.
If you have to logon to your email then you will need a username here and another line for password, MAPISession1.Password = Your password
Hope this helps
Later...
Here's the code I use to send an automated email in an app I am currently working on.
Place a MAPISession control on your form, call it MAPISession1.
Place a MAPIMessages control on the form and call it mail
Place the following code in a sub called send_mail()
strMailName = dtaEmail.Recordset.Fields(
strEmailName = dtaEmail.Recordset.Fields(
MAPISession1.LogonUI = False
MAPISession1.UserName = "MICROSOFT OUTLOOK"
MAPISession1.SignOn
mail.SessionID = MAPISession1.SessionID
mail.Compose
mail.RecipDisplayName = strMailName
mail.RecipAddress = strEmailName
mail.ResolveName
mail.MsgSubject = "File size changed!"
'Create the message
mail.MsgNoteText = strEmailMessage
mail.Send False
MAPISession1.SignOff
When your file size changes call send_mail
The strMailName and strEmailName are variables I set for the users email address and name because I send it to several people. I have a DB table that contains the names and addresses of the people I will send this to. I set my recordset equal to these fields. Field "0" is the user name and Field "1" is their email address.
I then will put the above code in a for/next loop moving through the recordset until I have sent all of the emails.
The strEmailMessage is the variable I set to hold the message text for the email.
The MAPISession1.UserName = "MICROSOFT OUTLOOK" assumes I am logged onto the network and calls OUTLOOK with my account info.
If you have to logon to your email then you will need a username here and another line for password, MAPISession1.Password = Your password
Hope this helps
Later...
ASKER
The VB send mail program works great, But I am monitoring a file using a loop, and it is causing my computer to lock up after it runs through the loop 10 times. Is there any other method of monitoring if a file length has been changed?
ASKER
Would it work if I used a timer so my program would not have to run through the loop all of the time. That way it would only run through after a set time
Use a timer instead of a loop. You should set the Interval property to 60000 so that the event will be triggered once a minute.
Yes use a timer to check on the file. It's cleaner than the loop. Then call the send mail and everything should work.
Later...
Later...
Working?
Please update this and finalize it. Expert closing recommendations appreciated.
Moondancer - EE Moderator
Moondancer - EE Moderator
points to me.
I provided the same solution to Dgassert. In fact, one step earlier than emoreau. I shall be awarded too.
Thank you, points have been split.
Points for ianouii -> https://www.experts-exchange.com/jsp/qShow.jsp?qid=20315442
Moondancer - EE Moderator
Points for ianouii -> https://www.experts-exchange.com/jsp/qShow.jsp?qid=20315442
Moondancer - EE Moderator
- Use FileSystemObject to check on your file size. MSDN (FileSystemObject)
- Use MAPI in VB. Refer to MSDN. It has a code sample with it.
good luck.