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?
Printable View
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?
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..
Code: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 protected]>" & vbCrLf & _
"RCPT TO: <" & txtTo & ">" & vbCrLf & _
"DATA" & vbCrLf & _
"TO: " & txtTo & vbCrLf & _
"FROM: <[email protected]>" & vbCrLf & _
"SUBJECT: " & txtSubject & vbCrLf & _
txtMsg & vbCrLf & "." & vbCrLf & _
"QUIT" & vbCrLf
End Sub
Private Sub Winsock1_SendComplete()
Caption = "Send Complete."
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
How would I connect to lets say...a Mailcity account to send the E-mail?
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?
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 = "[email protected]"
MAPIMessages1.Send
MAPISession1.SignOff
End Sub
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!
You also have to set the RecipDisplayName property:
MAPIMessages1.RecipDisplayName = MAPIMessages1.RecipAddress ' Or "John Doe" or whatever
Good luck!
------------------
Joacim Andersson
[email protected]
[email protected]
www.YellowBlazer.com
Joacim is right, you need to set the recipient display name. Thanks Joacim.
Whay if the person doesn't have a default e-mail program on their computer?
Juan Carlos
Try Send True
or Send False
That should make it work.
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?
why not use cdo, see the code i use, just make reference to the cdo library
vb Code:
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
@ 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.
@Nightwalker83,
I didn't realized the date. My bad!
It helped me today! Mail rules have changed since 1999, but it's still a valid question.
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
if using google,
server = smtp.gmail.com
[email protected]
password=your password
port=465
NOTE
make sure you enable smtp & pop in gmail under your account settings
Thanks, I'll give that a whirl!
"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!
make sure you set bSmtpSSL value to true
How are you using the functionCode:lobj_cdomsg.Configuration.Fields(cdoSMTPUseSSL) = bSmtpSSL
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
if you project is not big, attache it or the code you are using
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!
i made an example, please check here
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
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
vb Code:
.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
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