RobertoFreemano
asked on
outlook mailto with attachment vb.net 2003
Hi Experts,
Does anyone know an easy method to use maito function with an attachment. I've look everywhere and tried many code. I tried this (below) and it lauched a new message without an attachment,
Dim Addr As String = "user@address.com"
Dim Subject As String = "Subject"
Dim Body As String = "Body"
Dim Attach As String = "C:\Path\FileName.txt"
System.Diagnostics.Process .Start("ma ilto:" & Addr & "?subject=" & Subject & "&body=" & Body & "&attachment=" & Attach
Any ideas,
Roberto
Does anyone know an easy method to use maito function with an attachment. I've look everywhere and tried many code. I tried this (below) and it lauched a new message without an attachment,
Dim Addr As String = "user@address.com"
Dim Subject As String = "Subject"
Dim Body As String = "Body"
Dim Attach As String = "C:\Path\FileName.txt"
System.Diagnostics.Process
Any ideas,
Roberto
Try this:
Dim mail As New MailMessage()
mail.To = "me@mycompany.com"
mail.From = "you@yourcompany.com"
mail.Subject = "this is a test email."
mail.Body = "this is my test email body."
Dim attachment As New MailAttachment(Server.MapP ath("test. txt")) 'create the attachment
mail.Attachments.Add(attac hment) 'add the attachment
SmtpMail.SmtpServer = "localhost" 'your real server goes here
SmtpMail.Send(mail)
Dim mail As New MailMessage()
mail.To = "me@mycompany.com"
mail.From = "you@yourcompany.com"
mail.Subject = "this is a test email."
mail.Body = "this is my test email body."
Dim attachment As New MailAttachment(Server.MapP
mail.Attachments.Add(attac
SmtpMail.SmtpServer = "localhost" 'your real server goes here
SmtpMail.Send(mail)
ASKER
Hi,
I'm now getting 'MailMessage()'/ 'MailAttachment' and 'SmtpMail.SmtpServer' not defined.. this is the bit that gets me... can you please help?
Roberto
I'm now getting 'MailMessage()'/ 'MailAttachment' and 'SmtpMail.SmtpServer' not defined.. this is the bit that gets me... can you please help?
Roberto
Try this, you can do it without using SMTP, just add the reference: Microsoft Outlook 9.0 Object Library to your project.
Here is a function I use:
Mail_Out("yourname@xxxx.co m", "This is a test")
Function Mail_Out(ByVal EMailAddress As String, Optional ByVal EMailSubject As String = "", _
Optional ByVal EMailMessage As String = "")
Dim application As Outlook.Application
Dim objItem As Outlook.MailItem
application = CreateObject("Outlook.Appl ication")
objItem = application.CreateItem(Out look.OlIte mType.olMa ilItem)
objItem.Subject = EMailSubject
objItem.To = EMailAddress
objiteml.Attachments.Add(" c:\test.tx t", Outlook.OlAttachmentType.o lByValue)
objItem.Send()
application = Nothing
objItem = Nothing
End Function
Here is a function I use:
Mail_Out("yourname@xxxx.co
Function Mail_Out(ByVal EMailAddress As String, Optional ByVal EMailSubject As String = "", _
Optional ByVal EMailMessage As String = "")
Dim application As Outlook.Application
Dim objItem As Outlook.MailItem
application = CreateObject("Outlook.Appl
objItem = application.CreateItem(Out
objItem.Subject = EMailSubject
objItem.To = EMailAddress
objiteml.Attachments.Add("
objItem.Send()
application = Nothing
objItem = Nothing
End Function
ASKER
Hi rkckjk,
So far I've done exactly as you've suggested; however, the only line that is causing trouble is:
objiteml.Attachments.Add(" c:\test.tx t", Outlook.OlAttachmentType.o lByValue)
It states that objiteml is not declared... any ideas?
Roberto
P.s. I will increase points as I've neglected this solution :)
So far I've done exactly as you've suggested; however, the only line that is causing trouble is:
objiteml.Attachments.Add("
It states that objiteml is not declared... any ideas?
Roberto
P.s. I will increase points as I've neglected this solution :)
Sorry, it was typo in my part...
The line should be:
objitem.Attachments.Add("c :\test.txt ", Outlook.OlAttachmentType.o lByValue)
The line should be:
objitem.Attachments.Add("c
ASKER
Hi rkckjk,
I've amended the line and inserted the code on Button1. When Button1 is clicked, nothing appears to happen... should this launch Outlook?
Cheers,
Roberto
I've amended the line and inserted the code on Button1. When Button1 is clicked, nothing appears to happen... should this launch Outlook?
Cheers,
Roberto
Did you add Microsoft Outlook 9.0 Object Library as reference in your application?
ASKER
I think I added Microsoft Outlook 11 Object to it
Ok , here's my entire code and it worked great:
Module Module1
Sub Main()
Mail_Out("yourname@xxxx.co m", "This is a test")
End Sub
Function Mail_Out(ByVal EMailAddress As String, Optional ByVal EMailSubject As String = "", _
Optional ByVal EMailMessage As String = "")
Dim application As Outlook.Application
Dim objItem As Outlook.MailItem
application = CreateObject("Outlook.Appl ication")
objItem = application.CreateItem(Out look.OlIte mType.olMa ilItem)
objItem.Subject = EMailSubject
objItem.To = EMailAddress
objItem.Attachments.Add("c :\test.txt ", Outlook.OlAttachmentType.o lByValue)
objItem.Send()
application = Nothing
objItem = Nothing
End Function
End Module
Module Module1
Sub Main()
Mail_Out("yourname@xxxx.co
End Sub
Function Mail_Out(ByVal EMailAddress As String, Optional ByVal EMailSubject As String = "", _
Optional ByVal EMailMessage As String = "")
Dim application As Outlook.Application
Dim objItem As Outlook.MailItem
application = CreateObject("Outlook.Appl
objItem = application.CreateItem(Out
objItem.Subject = EMailSubject
objItem.To = EMailAddress
objItem.Attachments.Add("c
objItem.Send()
application = Nothing
objItem = Nothing
End Function
End Module
ASKER
Hi rkckjk,
I've created the module in pasted your code... but how do i call the event from module1 to a button1 on a Winform?
Sorry for being a total novice :(
Cheers,
Roberto
I've created the module in pasted your code... but how do i call the event from module1 to a button1 on a Winform?
Sorry for being a total novice :(
Cheers,
Roberto
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent rkckjk,
Many thanks
;)
Many thanks
;)
HTH