PDA

Click to See Complete Forum and Search --> : E-Mail in VB


HeLta_SkeLta
Oct 10th, 1999, 11:30 AM
I'm trying to make a program where all the user has to enter is the e-mail address to send the e-mail, the subject, and the message and it will send the e-mail with no problem.

Can anyone help me with this?

Aaron Young
Oct 10th, 1999, 11:42 AM
If you don't mind the User Pressing the Send Button you could launch the Default Mail Client using the ShellExecute API passing the Email, Subject and Message in the Command Line.

Otherwise you could use the Winsock Control to Access a Mail Server Directly, eg.

For this example you'll need a Winsock Control, Command Button and several Textboxes..

Private Sub cmdSend_Click()
Caption = "Sending Message.."
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Connect "Some.MailServer.com", 25
End Sub

Private Sub Winsock1_Connect()
Winsock1.SendData "HELO " & Winsock1.LocalIP & vbCrLf & _
"MAIL FROM: <Email@Somewhere.com>" & vbCrLf & _
"RCPT TO: <" & txtTo & ">" & vbCrLf & _
"DATA" & vbCrLf & _
"TO: " & txtTo & vbCrLf & _
"FROM: <Email@Somewhere.com>" & vbCrLf & _
"SUBJECT: " & txtSubject & vbCrLf & _
txtMsg & vbCrLf & "." & vbCrLf & _
"QUIT" & vbCrLf
End Sub

Private Sub Winsock1_SendComplete()
Caption = "Send Complete."
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

HeLta_SkeLta
Oct 11th, 1999, 08:10 AM
How would I connect to lets say...a Mailcity account to send the E-mail?

HeLta_SkeLta
Oct 11th, 1999, 08:27 AM
What i'm trying to do is make my program send the e-mail as a WWWPager to my icq. I know where to send it but what would I put for the mail server?

Morpheus Ronin
Oct 11th, 1999, 09:41 AM
The subprogram below utilizes a MAPI Session and MAPIMessage control from the MS MAPI 6.0 controls to send a message. It automatically opens the default email client (in the background) and sends a message using the specified information. It works well, I have used it in VB and in MS Access apps.


Private Sub SendEmail()
MAPISession1.SignOn
MAPIMessages1.SessionID = Me.MAPISession1.SessionID
MAPIMessages1.Compose
MAPIMessages1.MsgSubject = "Hey Hey"
MAPIMessages1.MsgNoteText = "This is the body of my email"
MAPIMessages1.RecipAddress = "jim@smith.net"
MAPIMessages1.Send
MAPISession1.SignOff
End Sub

Juan Carlos Rey
Oct 11th, 1999, 08:18 PM
Hi, Morpheus.

Your code doesn't work for me: when it reaches the line "MAPIMessages1.Send" I get error 32002 "error not specified". Is there anything wrong in the code? Am I missing something? Please, help! I need to be able to send e-mails automatically!

Joacim Andersson
Oct 11th, 1999, 10:01 PM
You also have to set the RecipDisplayName property:
MAPIMessages1.RecipDisplayName = MAPIMessages1.RecipAddress ' Or "John Doe" or whatever

Good luck!


------------------
Joacim Andersson
joacim@programmer.net
joacim@yellowblazer.com
www.YellowBlazer.com (http://www.YellowBlazer.com)

Morpheus Ronin
Oct 11th, 1999, 10:56 PM
Joacim is right, you need to set the recipient display name. Thanks Joacim.

HeLta_SkeLta
Oct 12th, 1999, 04:35 AM
Whay if the person doesn't have a default e-mail program on their computer?

Chris Perrin
Nov 23rd, 1999, 10:18 AM
Juan Carlos

Try Send True
or Send False

That should make it work.

Jennifer_R
Feb 11th, 2000, 05:17 AM
I think the above code is woderfull for my app however could someone please explain why my e-mail is not getting delivered. This Is the message I'm getting.
No transport provider was available for delivery to this recipient.
Also, what is ment by setting send = true?
Is that my line of code? send = true What does it do?

coolcurrent4u
Apr 13th, 2011, 03:58 AM
why not use cdo, see the code i use, just make reference to the cdo library



Public Function SendMail(sTo As String, sSubject As String, sFrom As String, _
sBody As String, sSmtpServer As String, iSmtpPort As Integer, _
sSmtpUser As String, sSmtpPword As String, _
sFilePath as string, bSmtpSSL As Boolean) As String

On Error GoTo SendMail_Error:

Dim lobj_cdomsg As CDO.Message
Set lobj_cdomsg = New CDO.Message
lobj_cdomsg.Configuration.Fields(cdoSMTPServer) = sSmtpServer
lobj_cdomsg.Configuration.Fields(cdoSMTPServerPort) = iSmtpPort
lobj_cdomsg.Configuration.Fields(cdoSMTPUseSSL) = bSmtpSSL
lobj_cdomsg.Configuration.Fields(cdoSMTPAuthenticate) = 1
lobj_cdomsg.Configuration.Fields(cdoSendUserName) = sSmtpUser
lobj_cdomsg.Configuration.Fields(cdoSendPassword) = sSmtpPword
lobj_cdomsg.Configuration.Fields(cdoSMTPConnectionTimeout) = 30
lobj_cdomsg.Configuration.Fields(cdoSendUsingMethod) = 2
lobj_cdomsg.Configuration.Fields.Update
lobj_cdomsg.To = sTo
lobj_cdomsg.From = sFrom
lobj_cdomsg.Subject = sSubject
lobj_cdomsg.TextBody = sBody
lobj_cdomsg.AddAttachment (sFilePath)
lobj_cdomsg.Send
Set lobj_cdomsg = Nothing
SendMail = "ok"
Exit Function
SendMail_Error:
SendMail = Err.Description
End Function

Nightwalker83
Apr 13th, 2011, 04:02 AM
@ coolcurrent4u,

While I am sure your post is helpful to someone please check the date of the last post before replying to a thread. This thread had been dead for 11 years before you replied to it.

TysonLPrice
Apr 13th, 2011, 04:23 AM
@ coolcurrent4u,

While I am sure your post is helpful to someone please check the date of the last post before replying to a thread. This thread had been dead for 11 years before you replied to it.

Officially it is not resolved :D

coolcurrent4u
Apr 13th, 2011, 05:10 AM
@Nightwalker83,

I didn't realized the date. My bad!

bren0098
Apr 13th, 2011, 07:55 AM
It helped me today! Mail rules have changed since 1999, but it's still a valid question.

vbfbryce
Apr 14th, 2011, 01:44 PM
Hey, Cool:

I've tried using code like this before, and never been successful.

What kind of values should I be feeding into the function, for example in the "server" and "port" fields, if I want to send through g mail?

Thanks!

vBryce

coolcurrent4u
Apr 14th, 2011, 02:17 PM
if using google,
server = smtp.gmail.com
username=youridl@gmail.com
password=your password
port=465

NOTE
make sure you enable smtp & pop in gmail under your account settings

vbfbryce
Apr 15th, 2011, 09:10 AM
Thanks, I'll give that a whirl!

vbfbryce
Apr 15th, 2011, 10:21 AM
"The transport failed to connect to the server."

This is the error message I get.

I used the settings you suggested in the earlier post, and attempted to enable both POP and SMTP in my g mail account, but I was a little unsure how to do that. I think I got the POP enabled, but didn't see where to enable SMTP. Can you point me to where that is done more specifically? Thanks again!

coolcurrent4u
Apr 16th, 2011, 09:35 AM
make sure you set bSmtpSSL value to true

lobj_cdomsg.Configuration.Fields(cdoSMTPUseSSL) = bSmtpSSL

How are you using the function

vbfbryce
Apr 18th, 2011, 09:52 AM
Cool,

I have that value set to "true."

I am using your cdo code, and calling is using parameters from text boxes. I have stepped through it to verify that I like the values that I'm feeding into it.

I'm stumped!

Bryce

coolcurrent4u
Apr 18th, 2011, 11:28 AM
if you project is not big, attache it or the code you are using

vbfbryce
Apr 18th, 2011, 12:49 PM
Hopefully this isn't a duplicate response. I tried to reply earlier, and it appears I wasn't successful.

Anyway, attached is my form.

Thanks!

coolcurrent4u
Apr 19th, 2011, 09:01 AM
i made an example, please check here (http://www.vbforums.com/showthread.php?p=3997338)

vbfbryce
Apr 21st, 2011, 07:25 AM
Cool,

Thanks for whipping that sample up.

I attached a shot of what values I'm inputting, and the resulting issue I still have.

Scratching my head!

Bryce

coolcurrent4u
Apr 22nd, 2011, 06:20 AM
Possible causes

slow internet connection
Firewall blocking you from sending mail with that port/domain/Ip of gmail
Server is rejecting your account from sending email

Possible solution

increase the timeout settings, the default is 30 seconds, change it to 60 or whatever you like
.Configuration.Fields(cdoSMTPConnectionTimeout) = 30 'change to 60
check you firewall and make sure it is not restricting the port/domain/Ip gmail
if possible create a new gmail/aol/gmx account and try again

vbfbryce
Apr 22nd, 2011, 08:02 AM
Cool,

Thanks again for all your help!

I'm thinking it must be my firewall, because the error message comes back relatively quickly regardless of how long I set the timeout for.

I'm going to try it on a different machine (with different firewall settings that I can actually adjust!).

Thanks!

Bryce