|
-
Aug 16th, 2006, 02:30 AM
#1
Thread Starter
Frenzied Member
[2005] Sending an email using Gmail?
Hello everyone,
It has been a while since i posted. Am now starting my VS2005 shoes 
I would like to send an email using VS2005 via Gmail.
I know that it is possible, but am puzzled on how to establish a secure SSL connection.
Below is extracted from the Gmail help site
To configure your client manually:
Open Outlook or Outlook Express.
Click the 'Tools' menu, and select 'Accounts...'
Click 'Add,' and then click 'Mail...'
Enter your name in the 'Display name:' field, and click 'Next.'
Enter your full Google Mail email address ([email protected]) in the 'Email address:' field, and click 'Next.'
Enter 'pop.googlemail.com' in the 'Incoming mail (POP3, IMAP or HTTP) server:' field. Enter 'smtp.googlemail.com' in the 'Outgoing mail (SMTP) server:' field.
Click 'Next.'
Enter your Google Mail username (including '@googlemail.com') in the 'Account name:' field. Enter your Google Mail password in the 'Password:' field, and click 'Next.'
Click 'Finish.'
Highlight 'pop.googlemail.com' under 'Account,' and click 'Properties.'
Click the 'Advanced' tab.
Tick the box next to 'This server requires a secure connection (SSL)' under 'Outgoing Mail (SMTP).'
Enter '465' in the 'Outgoing mail (SMTP):' field.
Tick the box next to 'This server requires a secure connection (SSL)' under 'Incoming mail (POP3).' The port will change to 995.
*The order of 'Outgoing' and 'Incoming' mail server fields varies by version. Make sure you enter the correct information in each field.
Click the 'Servers' tab, and tick the box next to 'My server requires authentication.'
Click 'OK.'
Congratulations!
Last edited by dinosaur_uk; Aug 24th, 2006 at 08:39 PM.
If you find my thread helpful, please remember to rate me 
-
Aug 16th, 2006, 10:25 AM
#2
Hyperactive Member
Re: [2005] Sending an email using Gmail?
I don't have 2005, but I'm sure if you look into some of the properties of the MailMessage object and SmtpClient object you will find your answers. He is some basic code I found in anohter thread.
VB Code:
Dim Mail As New MailMessage
With Mail
.Subject = "Some Subject"
.Body = "Some Body"
End With
Dim SMTP As New SmtpClient("SMTP.SOMESERVER.NET")
SMTP.Send(Mail)
' Cleanup
SMTP = Nothing
Mail.Dispose()
Visual Studio .NET 2005/.NET Framework 2.0
-
Aug 16th, 2006, 11:42 AM
#3
Thread Starter
Frenzied Member
Re: [2005] Sending an email using Gmail?
Ya...i know how to do that....just need to have a secure ssl connection
If you find my thread helpful, please remember to rate me 
-
Aug 16th, 2006, 12:09 PM
#4
Hyperactive Member
Re: [2005] Sending an email using Gmail?
Here is a link to some CDO configurations that worked for me in .net 1.1 I'm not sure if it has changed in 2.0. I did not use SSL, but see that it has item property. See this link http://msdn.microsoft.com/library/de...22bb7ce17c.asp. Just look on the left for a smtpusessl field and add it. I think you need to change the port too.
VB Code:
Dim CurrentMessage As New System.Web.Mail.MailMessage
Dim sSmtpMail As System.Web.Mail.SmtpMail
CurrentMessage.Subject = "Hello World"
CurrentMessage.Body = "Go to he doulbe L."
If File.Exists("F:\RepReports\S" & sPR.Trim & ".pdf") Then
Dim aAttachment As New System.Web.Mail.MailAttachment("F:\RepReports\S" & sPR.Trim & ".pdf", Mail.MailEncoding.Base64)
CurrentMessage.Attachments.Add(aAttachment)
attached = attached + " Shop Orders "
End If
CurrentMessage.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.ameritech.yahoo.com"
CurrentMessage.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
CurrentMessage.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
CurrentMessage.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
CurrentMessage.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = " [email protected]"
CurrentMessage.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxx"
sSmtpMail.SmtpServer = "smtp.ameritech.yahoo.com"
sSmtpMail.Send(CurrentMessage)
AddToList(sPR.Trim, "E-Mail Sent")
Visual Studio .NET 2005/.NET Framework 2.0
-
Aug 23rd, 2006, 12:34 AM
#5
Thread Starter
Frenzied Member
Re: [2005] Sending an email using Gmail?
OK....
i have managed to get this code from www.systemwebmail.net.
VB Code:
'create the mail message
Dim mail As New MailMessage()
'set the addresses
'set the content
mail.Subject = "This is an email"
mail.Body = "this is the body content of the email."
'send the message
Dim smtp As New SmtpClient("smtp.mail.yahoo.com", 587)
'to authenticate we set the username and password properites on the SmtpClient
smtp.Credentials = New Net.NetworkCredential("username", "Password")
smtp.Send(mail)
But it still does not work. How can i tell if my ISP is blocking the emails?
I am currently in china and it could be because of the restrictive ISP's that is why i cant connect to either yahoo or gmail smtp servers.
The yahoo servers require me to have a secure authentication apparently. Here is the error:
Anyone have any ideas?
If i put
I get this error
Server does not support secure connections.
What the heck is going on?
Cheers in advance!
If you find my thread helpful, please remember to rate me 
-
Aug 23rd, 2006, 12:37 AM
#6
Thread Starter
Frenzied Member
Re: [2005] Sending an email using Gmail?
Apparently, yahoo wants money if you want to use their smtp servers...
So i tried with Gmail, but no luck there either
If you find my thread helpful, please remember to rate me 
-
Aug 23rd, 2006, 01:04 AM
#7
Hyperactive Member
Re: [2005] Sending an email using Gmail?
take a look at this for reference. That way you dont need an outside smtp server to send mail:
http://www.vbdotnetheaven.com/Code/M...testserver.asp
-
Aug 23rd, 2006, 01:14 AM
#8
Thread Starter
Frenzied Member
Re: [2005] Sending an email using Gmail?
Nah, it doesn't work...
It still requires an external SMTP server to relay email messages to the outside work
If you find my thread helpful, please remember to rate me 
-
Aug 23rd, 2006, 09:07 AM
#9
Hyperactive Member
Re: [2005] Sending an email using Gmail?
Visual Studio .NET 2005/.NET Framework 2.0
-
Aug 23rd, 2006, 12:12 PM
#10
Thread Starter
Frenzied Member
Re: [2005] Sending an email using Gmail?
yup.....it has sorted my problem..
how can i get my program to run it? (and then minimise it...)
If you find my thread helpful, please remember to rate me 
-
Aug 24th, 2006, 08:38 PM
#11
Thread Starter
Frenzied Member
Re: [2005] Sending an email using Gmail?
Ok....i found an article on the net on how to get GMail to work with .Net 2.0
I will post my code shortly. It is excellent! No need for Freesmtp...
If you find my thread helpful, please remember to rate me 
-
Aug 25th, 2006, 09:32 AM
#12
Hyperactive Member
Re: [2005] Sending an email using Gmail?
hi every one I don't know why some one said
Apparently, yahoo wants money if you want to use their smtp servers.
but this code works perfectly
VB Code:
Dim username As String = us.Text
Dim domin As String
Dim body As String = bo.Text
Dim tooo As String = too.Text
Dim subject As String = subj.Text
Dim sender1 As String = se.Text
Select Case ListBox1.SelectedIndex
Case 0
domin = "gmail"
Case 1
domin = "hotmail"
Case 2
domin = "msn"
Case 3
domin = "yahoo"
End Select
If domin = "" Then
domin = dom.Text
End If
If domin = "" Then
MsgBox("You must select the website that you have ur E-mail id ", MsgBoxStyle.Information)
End If
Try
Dim message1, Conf, Fields, acsessing, sendemailgmail, dom
dom = "smtp." & domin & ".com"
message1 = CreateObject("CDO.Message")
Conf = CreateObject("CDO.Configuration")
Fields = Conf.Fields
acsessing = "http://schemas.microsoft.com/cdo/configuration/"
Fields.Item(acsessing & "sendusing") = 2
Fields.Item(acsessing & "smtpserver") = dom
Fields.Item(acsessing & "smtpserverport") = 465
Fields.Item(acsessing & "smtpauthenticate") = 1
Fields.Item(acsessing & "sendusername") = username
Fields.Item(acsessing & "sendpassword") = ps.Text
Fields.Item(acsessing & "smtpusessl") = 1
Fields.Update()
message1.To = tooo
message1.From = username
message1.Subject = subject
message1.HTMLBody = body
message1.Sender = sender1
message1.ReplyTo = username
message1.Configuration = Conf
ToolStripStatusLabel1.Text = "Message sending please wait"
sendemailgmail = message1.Send
MsgBox(" Your mail has been successfully sent", MsgBoxStyle.Information)
us.Text = ""
bo.Text = ""
too.Text = ""
subj.Text = ""
se.Text = ""
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
VS 2005 .....Framework SDK 3.0
"Its mostly the brave one who choose to not fight"
-
Aug 26th, 2006, 02:30 AM
#13
Thread Starter
Frenzied Member
Re: [2005] Sending an email using Gmail?
VB Code:
Imports System.Net.Mail
Imports System.Net.Security.AuthenticatedStream
Imports System.Net.Mime
Imports System.Threading
Imports System.Text
Public Class class_EMAIL
Private Shared mailSent As Boolean = False
Friend EmailSettings As SettingsStruct
Friend Structure SettingsStruct
Friend Recipent() As String
Friend From As String
Friend Subject As String
Friend Body As String
Friend Attachments() As String
End Structure
Friend formy As Helper.frmMain
Dim wait As New Helper.frmWait
Sub Authenticate()
wait.Show(formy)
Dim msg As New System.Net.Mail.MailMessage()
msg.From = New MailAddress(EmailSettings.From)
'this is the recepients
Dim i As Integer
For i = 0 To EmailSettings.Recipent.Length - 1
msg.To.Add(EmailSettings.Recipent(i).ToString)
Next
'set the content
msg.Subject = EmailSettings.Subject & Date.Now.ToShortDateString & " " & Date.Now.ToShortTimeString
msg.SubjectEncoding = System.Text.Encoding.UTF8
msg.Body = EmailSettings.Body 'Me.txtEmailBody.Text
msg.BodyEncoding = System.Text.Encoding.UTF8
msg.IsBodyHtml = False
msg.Priority = MailPriority.High
'add the creddentials
Dim client As New SmtpClient()
client.Credentials = New System.Net.NetworkCredential(" [email protected]", "PASSWORD")
client.Port = 587
client.Host = "smtp.gmail.com"
client.EnableSsl = True
AddHandler client.SendCompleted, AddressOf client_SendCompleted
Dim userState As Object = msg
Try
'you can also call client.Send(msg)
client.SendAsync(msg, userState)
Catch ex As System.Net.Mail.SmtpException
MessageBox.Show(ex.Message, "Send Mail Error")
End Try
End Sub 'SendMail
Sub client_SendCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
Dim mail As MailMessage = CType(e.UserState, MailMessage)
Dim subject As String = mail.Subject
If e.Cancelled Then
Dim cancelled As String = String.Format("[{0}] Send canceled.", subject)
MessageBox.Show(cancelled)
wait.Close()
End If
If Not (e.Error Is Nothing) Then
Dim [error] As String = [String].Format("[{0}] {1}", subject, e.Error.ToString())
MessageBox.Show([error])
wait.Close()
Else
MessageBox.Show("Message sent.")
wait.Close()
End If
mailSent = True
End Sub 'client_SendCompleted
End Class
Then to call onto this class,
VB Code:
Private Sub btnEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEmail.Click
Dim cls As New class_EMAIL
'We need to find out who r we sending to.
'and so on.....
cls.Authenticate()
End Sub
If you find my thread helpful, please remember to rate me 
-
Jan 1st, 2007, 02:52 PM
#14
-
Jan 1st, 2007, 10:10 PM
#15
Hyperactive Member
Re: [2005] Sending an email using Gmail?
well, that is because you do not have those forms in your project. Add a form to your project called frmMain, and one called frmWait and those reference errors will disappear.
-
Jan 2nd, 2007, 03:33 PM
#16
Hyperactive Member
Re: [2005] Sending an email using Gmail?
nope that doesnt work, any other suggestions???
VB Code:
Friend formy As Helper.frmMain
Dim wait As New Helper.frmWait
it is these two lines of code that fails
-
Jan 3rd, 2007, 11:16 AM
#17
-
Nov 2nd, 2007, 06:06 PM
#18
Hyperactive Member
Re: [2005] Sending an email using Gmail?
Code:
1.
Private Sub btnEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEmail.Click
2.
Dim cls As New class_EMAIL
3.
'We need to find out who r we sending to.
4.
cls.EmailSettings.Recipent= "[email protected]"
5.
'and so on.....
6.
7.
cls.Authenticate()
8.
End Sub
I'm getting this error for my e-mail recipient.
Error 1 Value of type 'String' cannot be converted to '1-dimensional array of String'.
I'm not sure what this means other than this is an array and it doesn't like the string that i have.
When I do it this way which i don't know why i would:
cls.EmailSettings.Recipent(1)= "[email protected]"
The error goes away but i get a null reference exception or something.
Object reference not set to an instance of an object.
Anyone help me out.?
Tuber
"I don't know the rules"
-
Nov 2nd, 2007, 06:11 PM
#19
Hyperactive Member
Re: [2005] Sending an email using Gmail?
Sorry I found it. I know what it was but i couldn't find it in the code.
The variable had () at the end. Probably from cutting and pasting.
Sorry.
Tuber
"I don't know the rules"
-
Nov 29th, 2007, 05:35 PM
#20
Thread Starter
Frenzied Member
Re: [2005] Sending an email using Gmail?
some info i copied from another site
1. Check these important settings:
a. My outgoing server requires authentication (or Password or
Challenge/Response for iMac)
b. Change the server timeout time from 1 min to 5 min
c. Uncheck leave a copy of email on server.
d. Try alternate SMTP port number: 25, 465, or 587.
e. Change the outgoing server to smtp.googlemail.com
2. Do you have a firewall blocking the connection? Email virus
checking? Popup Blocker? Temporarily disable them.
3. Update Outlook to latest configuration. Outlook 2000 should have
SP3. Outlook 2002 should have SP3. Outlook 2003 should have SP2.
4. Use the Captcha verification to unlock your account
https://www.google.com/accounts/DisplayUnlockCaptcha
5. See if the solutions here will help
http://www.slipstick.com/problems/nosend.htm
6. You ISP may be blocking Gmail server. Use your ISP SMTP server.
If you find my thread helpful, please remember to rate me 
-
Nov 29th, 2007, 09:50 PM
#21
Frenzied Member
Re: [2005] Sending an email using Gmail?
I got it to work with gmail but I had to run the unlock programme first. What does that actually do?
I used the settings from this link:
http://www.emailaddressmanager.com/t...-settings.html
-
Nov 29th, 2007, 10:40 PM
#22
Frenzied Member
Re: [2005] Sending an email using Gmail?
It appears that gmail ignores the specified "From Address" and replaces it with my gmail address.
If a user sends an email, I don't want replies to come to me - I want them to go back to the user.
Is there any way of changing this behaviour?
-
Nov 30th, 2007, 12:35 AM
#23
Frenzied Member
Re: [2005] Sending an email using Gmail?
It works perfectly using Yahoo and the following settings:
smtp.mail.yahoo.com
port 25
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
|