I have the following basic Send Object Macro.
Function McrSnapshotCallData()
On Error GoTo McrSnapshotCallData_Err
DoCmd.SendObject acQuery, "Qry_SnapShot", "Excel97-Excel2003Workbook(*.xls)", "xxx#xxx.com", "", "", "Calls", "Please find attached", False, ""
McrSnapshotCallData_Exit:
Exit Function
McrSnapshotCallData_Err:
MsgBox Error$
Resume McrSnapshotCallData_Exit
End Function
I need to be able to send run this macro on a server using a scheduler enabling an email to be sent out.
Currently this requires and outlook account on the server and it does not have one. Is it possible to include SMTP server details so this can be run automatically without me having to log on every night and send this.
Please can you me help adjust this if possible.
Sorry I am not very good with VBA stuff. Thanks
I can recommend these tools:
Blat: http://www.blat.net/ (free)
Blat is a Windows (32 & 64 bit) command line utility that sends eMail using SMTP.
Chilkat ActiveX libraries: http://www.chilkatsoft.com/email-features.asp (not free, but a lot more options)
MailMan: The Chilkat MailMan class is reponsible for sending email though SMTP and receiving/managing email on POP3 servers.
Email: Represents a complete Email object.
In both cases you'd first save the query as xls (DoCmd.TransferSpreadsheet) and then mail that file.
Related
My VB app can send an email to myself using the following code format:
Process.Start("mailto:test#myself.com&subject=somesubject&body=somebodytext")
This works well with email clients so far except Windows 10 Mail. For Mail the entire string is saved to the "To" line. What am I missing please?
"To" line: "test#myself.com?subject=somesubject&body=somebodytext"
Also, how best to test for Mail being the email client?
Is it possible to message another computers on a network via Excel VBA?
Example: If I save a shared Excel file on a network, it will send a message to other shared users whether they are using that shared file or not.
To send a message to other computers on the network (DOS window):
1.
msg /Server:serverName * /Time:5 "Message text..."
msg /Server:192.168.1.1 "Message text..."
Details (from Microsoft):
msg
{UserName|SessionName|SessionID|#FileName|*}
[/server:ServerName]
[/time:Seconds]
[/v]
[/w]
[Message]
2.
net send 192.168.0.1 "Message text..."
Details:
net send {name | * | /domain[:name] | /users} message
.
From VBA you can use something like this:
Dim result As Long
result = CreateObject("WScript.Shell").Run("msg /Server:192.168.1.1 'Message text...'")
Or this:
Shell("msg /Server:192.168.1.1 'Message text...'", vbNormalFocus)
.
PS. A shared file cannot send a message if it's inactive, but you can implement a VBA procedure that will automatically send a message to a list of named computers (or IP addresses) when someone opens the file (Workbook_Open() event of ThisWorkbook module) or when they access / edit certain cells on a sheet
The Excel VBA they may be running is running on their computers, you may not open the same files unless they are shared (even if shared I don't know how the variables stored in VBE are behaving).
Shared spreadsheets can be used to store variables, e.g. timestamps and userIDs (by the above description: in cells). You can have macros saved in them before sharing them that would check the variables and notify if something relevant ha happened.
Alternatively you can spam them all with emails from Excel to Outlook VBA.
I have a windows service that sends out emails by retriving the records from the database. The service account Windows Service is running under, is a Local admin on that machine. The issue i am having is somehow the windows service manages to send out some emails with pdf attachements that exist on the local server where windows service is located and for most of them i get an error message: Invalid Mail Attachment and having real difficulties what could be causing it? any idea on where should i start looking please?
Thanks
Try
' Initialize new mail message class
Dim objEmailMessage As New System.Net.Mail.MailMessage(EmailOutboxEntity.EmailFrom, EmailOutboxEntity.EmailTo)
' Set the email parameters
objEmailMessage.Subject = EmailOutboxEntity.EmailSubject
objEmailMessage.Body = EmailOutboxEntity.EmailBody
' Check if attachments have been specified
If Not EmailOutboxEntity.TestOriginalFieldValueForNull(EmailOutboxFieldIndex.EmailAttachements) Then
' Get an array of attachment file names to send
Dim arrAttachment As String() = Split(EmailOutboxEntity.EmailAttachements, CONST_AttachmentSeparator)
' Step through each filename and attach it to the email
For Each strAttachment As String In arrAttachment
' Attach the current file to the email
objEmailMessage.Attachments.Add(New System.Net.Mail.Attachment(strAttachment))
Next
End If
' Set the SMTP server
Dim mailServer As New System.Net.Mail.SmtpClient(pstrSMTPServer)
' Send the message
mailServer.Send(objEmailMessage)
Catch errException As Exception
' Throw an exception indicating the email failed to send
Throw New EmailOutboxManagerException(errException.Message, "Test Failed to send email, got the following error instead:")
End Try
Sorry Guys, as i have figured out the answer and it was my fault because i was running two different versions of the windows service on different servers and they were both picking up the attachments from the database and the path existed on one server where the files were saved and not on the other server and that's why some of the emails were managed to be sent.
I have two mailbox accounts in Outlook 2010.
Primary: Bob#something.com
Secondary: help#something.com
Every time I receive new mail to help#something.com I get the envelope of new mail.
I want to receive the envelope only for Bob#something.com
I cancelled the option to receive envelopes in Outlook.
I created a rule in Outlook 2010 under the account of Bob#something.com
I have the option to run a script but its empty.
I need to write VBA code that can do it:
If (mail was send to Bob#something.com) Then
show Envelope
End If
I know that I can just add the folder of help#something.com instead of its account but it is not possible in my environment (cloud users).
I searched on the web and didn't find anything like this. For example, I did not find what code line can turn the envelope on in Windows.
If you find displaying a message box is an acceptable alternative then the Run a Script format is described here Outlook's Rules and Alerts: Run a Script
From the rule you pass the new mail as "Item" like this:
Public Sub DisplayMessageBox(Item As Outlook.MailItem)
' You need not do anything with "Item" just use it as a trigger
MsgBox "New mail in Bob#something.com"
' or you can enhance the message using "Item" properties
MsgBox "New mail in Bob#something.com - Subject: " & Item.Subject
End Sub
You may also consider ItemAdd or NewMailEx which are a little more complex.
There is an ItemAdd example here How do I trigger a macro to run after a new mail is received in Outlook?
About a year ago, a manager in another department brainstormed that I could code up some VBA to auto call me in the event one of my automated reports crashes. I laughed at the time, but my skills have improved considerably and I wonder if it's technically possible
(not that I'd actually do it, mind you. I like my early Saturday mornings workplace-free).
This would need:
1. Access to the internet (not a problem)
2. A means of connecting to some service to place the call, preferably free, lest I cost the company $10 a month (Skype?)
3. An automated voice (already exists on the standard Access install package)
What do you think?
Edited 08/24/2009 - Spacing added. No text was changed.
Do the simplest thing that could possibly work. In this case, making phonecalls is hard, but sending emails is easy.
Most cellphone providers expose a phone's mailbox (something like 555-867-5309#cellphoneprovider.com) to the internet, allowing you to send an email to that address and have it show up on your phone as a text message.
You can use Skype in combination with VBA. It's actually not that complicated and you will find a couple of samples written in VBScript on the Skype website. I don't know whether it is possible to actually play an audio file, but you can send SMS easily:
'// Create a Skype4COM object:
Set oSkype = WScript.CreateObject("Skype4COM.Skype", "Skype_")
'// Start the Skype client:
If Not oSkype.Client.IsRunning Then oSkype.Client.Start() End If
'// Send SMS:
Set oSMS = oSkype.SendSms("+1234567890", "Hello!")
WScript.Sleep(60000)
'// Message event handler:
Public Sub Skype_SmsMessageStatusChanged(ByRef aSms, ByVal aStatus)
WScript.Echo ">Sms " & aSms.Id & " status " & aStatus & " " & oSkype.Convert.SmsMessageStatusToText(aStatus)
End Sub
'// Target event handler:
Public Sub Skype_SmsTargetStatusChanged(ByRef aTarget, ByVal aStatus)
WScript.Echo ">Sms " & aTarget.Message.Id & " target " & aTarget.Number & " status " & aStatus & " " & oSkype.Convert.SmsTargetStatusToText(aStatus)
End Sub
If you have a old dial up modem, then you could (in 'old VB6 days) dial via the modem programmatically, however I'm not sure if its possible in VBA. The next challange would be to get the audio down the line.
I would suggest that you butcher a headless earphone & microphone that connects to phones, you could then take a 3.5mm audio jack from your PC speaker output and connect this to the headless earphone/microphone set, unless there are cables that already do that (possibly).
Then it would be a simple matter of coding up Microsofts 'text to speech' engine.
Darknight
http://chandoo.org/wp/2009/02/05/twitter-from-excel/. Set up a twitter account that pings your phone and create twitters with this.
It's not as easy as the email idea, but you could be the first person to tweet from Excel for a reason other than novelty.
Another quite simple option is to send yourself a text message which is almost but not quite as easy to do as sending an email, but much easier to recieve. Companies such as clickatell.com provide cheap web based text services with good api's where once you are signed up all you need do is call a URL and you can send a text message.
Well worth a try.