Can i send email through Visual Basic ?
Thankx
Printable View
Can i send email through Visual Basic ?
Thankx
absolutely. Do a search --- there's a ton of stuff on it.
also might want to look on planet source code for examples
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
[Colorized by Cimperiali for better reading]Code:Dim objOutlook As Object
Dim objOutlookMsg As Object
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(0)
With objOutlookMsg
.To = "[email protected]
.Cc = "[email protected]"
.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
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.
From somewhere in this forum
[Colorized by Cimperiali for better reading]Code:Private Sub cmdEmail_Click()
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
MAPIMessages1.RecipAddress = "[email protected]"
MAPIMessages1.ResolveName
MAPIMessages1.MsgSubject = "Message Subject"
MAPIMessages1.MsgNoteText = "Hello World"
MAPIMessages1.Send False
MAPISession1.SignOff
End Sub
well this source code is impartial.
what references does it need? i can nowhere find a MAPI dll.
thanks
It is OCX control,
find it (Microsoft Mapi controls), place to form and use
as control.
Quote:
Originally posted by alexr123
well this source code is impartial.
what references does it need? i can nowhere find a MAPI dll.
thanks
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?
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 = "[email protected]"
SMTP.ReplyTo = "[email protected]"
SMTP.Subject = "Subject"
SMTP.BodyFormat = 0 'Text Format [1=HTML]
SMTP.BodyText = "Body"
SMTP.AddRecipient "Recipient Name", "[email protected]", 0
If SMTP.SendMail() = 0 Then
MsgBox "Message Sent!"
Else
MsgBox "Error Sending Message!" & vbCr & SMTP.GetLastError & ": " _
& SMTP.GetLastErrDescription
End If
Set SMTP = Nothing
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
Would somebody please be able to write details of each line of the above code. I do not understand what "resolvename" does.Quote:
Originally Posted by Platinum Plus
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.
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
you need to increment attachmentindex: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.Code:MAPIMessages1.AttachmentIndex = .AttachmentIndex + 1
MAPIMessages1.AttachmentPathName = Trim(adoFileType.Recordset!additionalAttach)
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).
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 :p
regards
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 :wave:
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: [email protected]", "rcpt to: [email protected]", 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.
Why not try vbsendmail.dll, it's been around for a while now, with full source code, only need winsock.
You can find it in this link
http://www.freevbcode.com/ShowCode.Asp?ID=109
thanks Luthv and Zeb..
it just coincedent or vbsendmail that u and Zeb talking are the same?
well..i guess i'm gonna give it a try...
thanks again
no coincidence - it's a pretty commonly used dll cause it is so much better than MAPI
Hi all,
I seem to have problems tackling the security issues of the Microsoft Outlook as the window on
"A program is trying to automatically send emails on your behalf.
Do you allow this?
If this is unexpected, it may be a virus and you should choose "No"."
I have searched through msdn pages, and found this url.
http://msdn.microsoft.com/library/de...mmatically.asp
However, the security features on my Microsoft Outlook is disabled. So how is it possible to still get this message? what else can I do?
Thanx. Need the help i could get!
I'm afraid you can't do anything.
Older versions of Outlook didn't have that feature but Microsoft added it for extra security.
I strongly recommend that you use vbSendMail.dll (see posts above).
This may help you out. It only uses winsock:
http://www.codeguru.com/forum/showth...562#post685872
Well i realised i cant get past the outlook thingy. So the best way is probably to use SMTP which i did.
Dim iMsg As New CDO.Message
Dim iConf As New CDO.Configuration
Dim Flds
Set Flds = iConf.Fields
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = SMTPServer
'Use SSL to connect to the SMTP server:
.Item(cdoSMTPServerPort) = SMTPPort
.Item(cdoSMTPConnectionTimeout) = 10
.Update
End With
With iMsg
Set .Configuration = iConf
.To = ReceiveBY
.From = SendBY
.Subject = strSubj
.HTMLBody = strBody
End With
And it works fine and save me all the trouble of finding ways to bypass the outlook security. But anyway thanx guys for the help.
Actually, you can bypass the Outlook warning messages. ContextMagic has written a freeware program called ClickYes that essentially suppresses the Outlook warnings. The following link allows you to download the program and offers instructions on how to implement its use in various programming languages. http://www.contextmagic.com/express-clickyes/Quote:
Originally Posted by babtbaby
Naturally, due to inherent risks from viruses I'd recommend using this program only when absolutely necessary (i.e. if Outlook is your only option for sending email), otherwise keep it turned off.
Here is that tricky code that will allow you to get past the Outlook security box when auto-sending emails thru a program. It puts an Icon on the task tray that you can set the activation on. It is called ClickYesSetup. I didn't attach it because it is an executable and we all are wary of those.
But, you can google it and it will come up. This will save a tone of time when your program has to send out more than just a few emails
Al
when I use this code to send mail,my McFee displayes the "Protocol Error" message.
I am using this code.
Private Sub Command1_Click()
MAPISession1.SignOn
MAPIMessages1.SessionID = MAPISession1.SessionID
MAPIMessages1.Compose
MAPIMessages1.RecipAddress = "[email protected]"
MAPIMessages1.ResolveName
MAPIMessages1.MsgSubject = "Message Subject"
MAPIMessages1.MsgNoteText = "Hello World"
MAPIMessages1.Send False
MAPISession1.SignOff
End Sub
plz tel me the solution quicky.
I have run the following code a number of times,the code runs correctly, no error msg.but after some time my McFee display that a mail to specified person with subject is beaing sent,but with a protocol msg,So, I Uninstall the McFe. sut still I am unable to sent mail.I have run code from "Bnoyzy"but still.....
I am getting no msg ,but unable to send mail.
plz tell me the sol.