Send email without Outlook support (1 Viewer)

Moore71

DEVELOPER
Local time
Today, 21:09
Joined
Jul 14, 2012
Messages
158
Hi,
forgive me for asking this question again. I know this issue have been attended to many times. But I still cannot get it done.


I have an ms-access form to send email without outlook support, using vba. The following are the items on the form:
textbox(From)
textbox(To)
textbox(subject)
body(Message)
Button(Send)


The recipient(To) is gmail with the following details:
Body(can be any Message)

username: someone@gmail.com
Password: somepassword


Now puzzle is can someone give me a sample VBA and sample form to send this message to gmail with all the security and ssl/tls set?


Thanks.
I will be very grateful, if my request finds favor and quick response.
 

MarkK

bit cruncher
Local time
Today, 13:09
Joined
Mar 17, 2004
Messages
8,179
I know this issue have been attended to many times.
Have you looked at one of the posts where this issue has been attended to? Is there a problem with what you have found there?

But I still cannot get it done.
Can you describe in greater detail the problem(s) you encounter? Show us a sample of your code, perhaps, and the details of how it fails.

hth
Mark
 

Moore71

DEVELOPER
Local time
Today, 21:09
Joined
Jul 14, 2012
Messages
158
Thank you for quick response.
It seems as if I don't know how to configure it well. The one I downloaded keeps telling me unable to connect to server or so and so port unreachable


That's why I need a fresh sample form with detailed configuration to have it setup
 

MarkK

bit cruncher
Local time
Today, 13:09
Joined
Mar 17, 2004
Messages
8,179
With respect, you have not given enough information. Maybe you have a problem with your code. Maybe you have a problem with the ports that your code sends to the smtp server. Without you doing a clearer job of expressing the exact specifics of the problem, there is a fair risk that I will waste both of our time by guessing.

If you have code, what I recommend is that you show the code. If you have errors or if you get error messages when you run the code, please tell us exactly what those messages are, and what lines cause those errors.

Without you providing that information, we are all just shooting in the dark.

Hope this helps,
Mark
 

Moore71

DEVELOPER
Local time
Today, 21:09
Joined
Jul 14, 2012
Messages
158
Sorry, this the correct format:


Private Sub cmdSend_Click()

If Trim(txtServer) = "" Then

MsgBox "Enter the server name or IP address"

txtServer.SetFocus
Exit Sub

ElseIf Trim(txtMailFrom) = "" Then

MsgBox "Enter the sender e-mail address"

txtMailFrom.SetFocus

Exit Sub

ElseIf Trim(txtSendTo) = "" Then

MsgBox "Enter the recipient e-mail address"

txtSendTo.SetFocus

Exit Sub
ElseIf cmbAuth.ListIndex = 1 And Trim(txtPOPServer) = "" Then

MsgBox "POP Authentication requires POP server"

txtPOPServer.SetFocus

Exit Sub

End If

If Trim(txtMessageSubject) = "" Then
If MsgBox("You didn't enter the message subject. " & vbCrLf & _

"Would you like to send it anyway?", vbYesNo) = vbNo Then
Exit Sub
End If

If Trim(txtMessageText) = "" Then
If MsgBox("You didn't enter the message text. " & vbCrLf & _

"Would you like to send it anyway?", vbYesNo) = vbNo Then
Exit Sub
End If


' txtStatus.SetFocus
With oSMTP 'authentication

If cmbAuth.ListIndex > 0 Then
.username = txtUsername
.password = txtPassword
End If

If cmbAuth.ListIndex = 1 Then
.POPServer = txtPOPServer
.AuthenticationType = cmbAuth.ListIndex
.Server = txtServer
.MailFrom = txtMailFrom
.SendTo = txtSendTo
.MessageSubject = txtMessageSubject
.MessageText = txtMessageText

If Me.Text40 > "" Then
.Attachments.Add Me.Text40
End If

If Me.Text44 > "" Then
.Attachments.Add Me.Text44
End If

If Me.Text47 > "" Then
.Attachments.Add Me.Text47
End If
----------------------------------------------------------------
My question now is where do I enter my
gmail username/password and supposing I
need an interface (User Form) to send this email,
how do I go about it?
Do I place this code on a form?
What will be the fields required in the form?
 
Last edited:

MarkK

bit cruncher
Local time
Today, 13:09
Joined
Mar 17, 2004
Messages
8,179
AhhlolyessothereisthecodeWhatIrecommendisthatyougothroughitandmakeitreadablesowecanworkwithitTotallyyourcallallthebestMark
 

Moore71

DEVELOPER
Local time
Today, 21:09
Joined
Jul 14, 2012
Messages
158
Sorry, this is the formatted VBA code:
I need someone to help me create a form to send this email without Outlook support and input the login details as it aught to be.
Thank you once again.

------------------------------------------------------------------------------------------------

Private Sub cmdSend_Click()

If Trim(txtServer) = "" Then

MsgBox "Enter the server name or IP address"

txtServer.SetFocus
Exit Sub

ElseIf Trim(txtMailFrom) = "" Then

MsgBox "Enter the sender e-mail address"

txtMailFrom.SetFocus

Exit Sub

ElseIf Trim(txtSendTo) = "" Then

MsgBox "Enter the recipient e-mail address"

txtSendTo.SetFocus

Exit Sub
ElseIf cmbAuth.ListIndex = 1 And Trim(txtPOPServer) = "" Then

MsgBox "POP Authentication requires POP server"

txtPOPServer.SetFocus

Exit Sub

End If

If Trim(txtMessageSubject) = "" Then

If MsgBox("You didn't enter the message subject. " & vbCrLf & _

"Would you like to send it anyway?", vbYesNo) = vbNo Then
Exit Sub

End If

If Trim(txtMessageText) = "" Then

If MsgBox("You didn't enter the message text. " & vbCrLf & _
"Would you like to send it anyway?", vbYesNo) = vbNo Then

Exit Sub

End If
' txtStatus.SetFocus
With oSMTP 'authentication

If cmbAuth.ListIndex > 0 Then

.username = txtUsername

.password = txtPassword

End If

If cmbAuth.ListIndex = 1 Then

.POPServer = txtPOPServer

.AuthenticationType = cmbAuth.ListIndex

.Server = txtServer

.MailFrom = txtMailFrom

.SendTo = txtSendTo

.MessageSubject = txtMessageSubject

.MessageText = txtMessageText

If Me.Text40 > "" Then

.Attachments.Add Me.Text40

End If

If Me.Text44 > "" Then

.Attachments.Add Me.Text44

End If

If Me.Text47 > "" Then

.Attachments.Add Me.Text47

End If
 

isladogs

MVP / VIP
Local time
Today, 21:09
Joined
Jan 14, 2017
Messages
18,209
This is your code using code tags & with added indenting to make it readable:
I haven't read it in detail but I can tell its incomplete
Missing End If / End With / End Sub .... and possibly other code?


Code:
Private Sub cmdSend_Click() 

If Trim(txtServer) = "" Then 
	MsgBox "Enter the server name or IP address" 
	txtServer.SetFocus
	Exit Sub 
ElseIf Trim(txtMailFrom) = "" Then 
	MsgBox "Enter the sender e-mail address" 
	txtMailFrom.SetFocus 
	Exit Sub 
ElseIf Trim(txtSendTo) = "" Then 
	MsgBox "Enter the recipient e-mail address" 
	txtSendTo.SetFocus 
	Exit Sub
ElseIf cmbAuth.ListIndex = 1 And Trim(txtPOPServer) = "" Then 
	MsgBox "POP Authentication requires POP server" 
	txtPOPServer.SetFocus 
	Exit Sub 
End If 

If Trim(txtMessageSubject) = "" Then 
	If MsgBox("You didn't enter the message subject. " & vbCrLf & _ 
	"Would you like to send it anyway?", vbYesNo) = vbNo Then 
	Exit Sub 
End If 

If Trim(txtMessageText) = "" Then 
	If MsgBox("You didn't enter the message text. " & vbCrLf & _
	"Would you like to send it anyway?", vbYesNo) = vbNo Then 
	Exit Sub 
End If

' txtStatus.SetFocus
[COLOR="Red"][B]With oSMTP 'authentication [/B][/COLOR]
	If cmbAuth.ListIndex > 0 Then 
		.username = txtUsername 
		.password = txtPassword 
	End If 

	[B][COLOR="red"]If cmbAuth.ListIndex = 1 Then [/COLOR][/B]
		.POPServer = txtPOPServer 
		.AuthenticationType = cmbAuth.ListIndex 
		.Server = txtServer 
		.MailFrom = txtMailFrom 
		.SendTo = txtSendTo 
		.MessageSubject = txtMessageSubject 
		.MessageText = txtMessageText 

		If Me.Text40 > "" Then 
			.Attachments.Add Me.Text40 
		End If 

		If Me.Text44 > "" Then 
			.Attachments.Add Me.Text44 
		End If 

		If Me.Text47 > "" Then 
			.Attachments.Add Me.Text47 
		End If

[COLOR="SeaGreen"]'the following lines were all missing - anything else as well?[/COLOR]
[B][COLOR="Red"][INDENT]End If[/INDENT]
End With

End Sub[/COLOR][/B]

You need to help us to help you!
 

bastanu

AWF VIP
Local time
Today, 13:09
Joined
Apr 13, 2010
Messages
1,402
Here is a sample db to send emails using GMail (uses CDO so the code might be similar to Colin's).

Cheers,
Vlad
 

Attachments

  • popGmail_Email.zip
    24.3 KB · Views: 212

isladogs

MVP / VIP
Local time
Today, 21:09
Joined
Jan 14, 2017
Messages
18,209
Hi Vlad
As its also CDO, the code is almost identical.
I hadn't realised port 465 was also used for gmail - same as my BTInternet email
 

bastanu

AWF VIP
Local time
Today, 13:09
Joined
Apr 13, 2010
Messages
1,402
Hi Colin, 465 is the SSL port.
Cheers,
Vlad
 

MarkK

bit cruncher
Local time
Today, 13:09
Joined
Mar 17, 2004
Messages
8,179
I need someone to help me create a form to send this email...
I still do not understand your exact requirement here. Are you having trouble creating a form? Are you having trouble adding controls to the form? Are you having trouble getting the data from the form controls to the CDO code? What is the exact problem? It sounds like it is not a problem with the CDO code specifically. Or is it simply a problem of not knowing the ports to use for GMail servers?
You can see how the solutions for each of those stated problems is distinct. So not knowing the exact problem disables us from helping.
Hope this helps,
Mark
 

Users who are viewing this thread

Top Bottom