-
September 11th, 2002, 10:36 AM
#1
Email with VB
Can i send email through Visual Basic ?
Thankx
-
September 11th, 2002, 02:31 PM
#2
absolutely. Do a search --- there's a ton of stuff on it.
also might want to look on planet source code for examples
phinds
vs2008, 3.5SP1 Version 9.0.21022.8 RTM
-
September 11th, 2002, 04:51 PM
#3
here's something I saved off some time ago. Don't remember if I ever tried it:
The simplest code to send emails is this: (need you have installed the Outlook
Code:
Dim objOutlook As Object
Dim objOutlookMsg As Object
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(0)
With objOutlookMsg
.To = "you@email.com
.Cc = "ifneed@copy.com"
.Subject = "Hello World (one more time)..."
.Body = "This is the body of message"
.HTMLBody = "HTML version of message"
.Attachments.Add ("c:\myFileToSend.txt")
.Send 'Let´s go!
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
[Colorized by Cimperiali for better reading]
Last edited by Cimperiali; December 7th, 2002 at 05:29 AM.
phinds
vs2008, 3.5SP1 Version 9.0.21022.8 RTM
-
September 11th, 2002, 07:20 PM
#4
Why don't you just use the MAPI Controls (MAPISession and MAPIMessages)? That's what they are for -- to send and receive email.
If you use the Outlook Express type libraries your app will only work on computers that have Outlook Express installed.
-
September 12th, 2002, 02:50 AM
#5
From somewhere in this forum
Code:
Private Sub cmdEmail_Click()
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
MAPIMessages1.RecipAddress = "successtory@hotmail.com"
MAPIMessages1.ResolveName
MAPIMessages1.MsgSubject = "Message Subject"
MAPIMessages1.MsgNoteText = "Hello World"
MAPIMessages1.Send False
MAPISession1.SignOff
End Sub
[Colorized by Cimperiali for better reading]
Last edited by Cimperiali; December 7th, 2002 at 05:31 AM.
-
February 16th, 2003, 10:05 AM
#6
well this source code is impartial.
what references does it need? i can nowhere find a MAPI dll.
thanks
-
February 16th, 2003, 04:34 PM
#7
It is OCX control,
find it (Microsoft Mapi controls), place to form and use
as control.
Originally posted by alexr123
well this source code is impartial.
what references does it need? i can nowhere find a MAPI dll.
thanks
-
December 8th, 2003, 11:59 PM
#8
Just wondering... That MAPI.send false line... Does that actually send it off? Kinda ironic that FALSE will actually do the sending
EDIT:
Okay I just tried it... And it appears that it does so in deed send But another problem arises... Outlook will prompt you if you want to send a message... Is there anyway to just use a SMTP server to send off a message?
Last edited by Randuin; December 9th, 2003 at 12:05 AM.
-
December 9th, 2003, 04:41 PM
#9
I don't know if this will help, but here's the SMTP code that I used:
Code:
Dim SMTP As ANSMTPLib.OBJ
Set SMTP = New ANSMTPLib.OBJ
SMTP.ServerAddr = "mail.server.com"
SMTP.RegisterKey = 'Fill in your register key if you have one
SMTP.FromAddr = "from@server.com"
SMTP.ReplyTo = "replyto@server.com"
SMTP.Subject = "Subject"
SMTP.BodyFormat = 0 'Text Format [1=HTML]
SMTP.BodyText = "Body"
SMTP.AddRecipient "Recipient Name", "recipient@server.com", 0
If SMTP.SendMail() = 0 Then
MsgBox "Message Sent!"
Else
MsgBox "Error Sending Message!" & vbCr & SMTP.GetLastError & ": " _
& SMTP.GetLastErrDescription
End If
Set SMTP = Nothing
I'd rather be wakeboarding...
-
December 10th, 2003, 02:30 AM
#10
What version of VB are you using and what extra namespace/controls did you reference to? I can't seem to define as an ANSMTPLib o.O
-
November 11th, 2004, 06:54 AM
#11
Re: Email with VB
Originally Posted by Platinum Plus
From somewhere in this forum
Code:
Private Sub cmdEmail_Click()
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
MAPIMessages1.RecipAddress = "successtory@hotmail.com"
MAPIMessages1.ResolveName
MAPIMessages1.MsgSubject = "Message Subject"
MAPIMessages1.MsgNoteText = "Hello World"
MAPIMessages1.Send False
MAPISession1.SignOff
End Sub
[Colorized by Cimperiali for better reading]
Would somebody please be able to write details of each line of the above code. I do not understand what "resolvename" does.
Also I need to know how to add over 1 attachment, being a noob and all I tried:
MAPIMessages1.AttachmentPathName = "C:\hello.txt" & "C:\hello2.txt"
but it dont work, and if 2 cases of AttachmentPathName is made it only sends the last attachment.
Last edited by Bnoyzy; November 11th, 2004 at 07:02 AM.
-
November 11th, 2004, 09:19 AM
#12
Re: Email with VB
You can forget about MAPI and Outlook (unless you only want to sent a couple of emails)
Microsoft have provided a popup message which forces you to confirm that you want to programatically control outlook via an external program. This means you need to keep clicking buttons for every email sent. (great if you like clicking)
This feature came in when Microsoft lost the plot about how to control the likes of the "Luv Virus" etc. (Around Outlook 2002)
You can always install Outlook 2000 to get around this feature. (or find a tricky bit of code which automatically provides a click for you - they do exist)
The other alternative is to bypass all this by using SMTP - just watch out for the fact that SMTP will not keep a copy in Outlook's sent box as it does not use Outlook.
Normally if you are automatically broadcasting lots of addresses with the same email, then you probably don't want a copy anyway.
If you really do want a copy, then you could always automatically send yourself a copy of the email using the CC: or BCC: addresses
-
November 11th, 2004, 04:20 PM
#13
Re: Email with VB
you need to increment attachmentindex:
Code:
MAPIMessages1.AttachmentIndex = .AttachmentIndex + 1
MAPIMessages1.AttachmentPathName = Trim(adoFileType.Recordset!additionalAttach)
BUT, I would suggest following everyone elses advice and ditch MAPI all together. It's on the out and has a number of issues and holes in it's functionality before you even get near the Outlook problems with having to confirm each send.
do a search for "vbsendmail". it's a dll that you can call that does it all for you and is very good - and best of all, I think it is free! It's well documented and has far more features than mapi provides, and even if you have got 95% through your MAPI implementation, I would still suggest scrapping that and using something else (like VbSendMail).
-
November 11th, 2004, 08:56 PM
#14
Re: Email with VB
maybe it's a good .dll but i need the code in it so that i can learn how to do stuff
i can manage to send via outlook app..but like George1111 said..it's need to click a button to send an email..
does anyone have a sample code that can be used to send email via anything that can send to every email server (yahoo, hotmail, etc)..coz it seems the code work for hotmail but not for yahoo..
i've tried the FAQ's but it just work for the Outlook stuff..
i'm not familiar with this before..so maybe it's like a dumb question
regards
-
November 11th, 2004, 11:40 PM
#15
Re: Email with VB
Erick - check this out:
http://www.microsoft.com/technet/arc...oy/d5smtp.mspx
get down to the bit about "Verifying the SMTP service" and see if that helps you.
i'm trying to do this in .Net at the moment, and getting great success with internal addresses, but can't send externally, so trying to fix it I found this which may help you
anyway, there are heaps of ways to send email. you can use Outlook, Mapi (which uses your client anyway), external dlls like the one I mentioned above, or you could even telnet to an smtp server and send the commands down that ("mail from: zeb@blah.blah.net", "rcpt to: erick@blah.blah.org", so on - i don't know them all).
one bit in the article that was interesting is the "pickup directory". anyway, maybe it helps, maybe it doesn't. i guess it comes down to whether you guys use your own mail server or an ISP.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|