What is the easiest way to send emails? I had found a way a couple weeks ago, and searching the site doesn't do me any good, because none of the examples work |
| cjk1 Wednesday, November 14, 2007 7:22 PM |
here you go. if u use gmail, works fine!
Code Block
Imports System.Net.Mail Imports System.Web
'sending Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim theMailMessage As MailMessage = New MailMessage("from", "To")
With theMailMessage .Body = RichTextBox1.Text .Subject = TextBox3.Text End With
'E-Mail Credentials and Sending Dim theClient As SmtpClient = New SmtpClient("SMTPprovider", 587) theClient.Timeout = 30000 theClient.EnableSsl = True
Dim theCredential As System.Net.NetworkCredential = New System.Net.NetworkCredential("userName", "password") theClient.Credentials = theCredential
'Send the email theClient.Send(theMailMessage) MessageBox.Show(("E-Mail Sent Successfully!" _ + (Environment.NewLine + "Thank You")), "Confirmation", MessageBoxButtons.OK)
Catch smtpex As SmtpException MessageBox.Show(("An error occured when trying to send a mail. You appear to be disconnected from the Internet. Pleas" & _ "e confirm that you are connected to the Internet and Resubmit all the data. " + smtpex.Message)) Catch ex As System.Exception MessageBox.Show(("An unexpected error occured. " + ex.Message))
End Try
End Sub |
| mNero Wednesday, November 14, 2007 7:40 PM |
Hello:
I use Microsoft Outlook, and the code I use is:
Imports Outlook = Microsoft.Office.Interop.Outlook ' At the General Section of the Form
Private Sub cmdMail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMail.Click
Dim oOutlook As New Outlook.Application
Dim olNs As Outlook.NameSpace
Dim oMail As Outlook.MailItem
oOutlook = CreateObject( "Outlook.Application")
olNs = oOutlook.GetNamespace( "MAPI")
olNs.Logon()
oMail = oOutlook.CreateItem(Outlook.OlItemType.olMailItem)
oMail.Subject = "Subject of the mail"
oMail.Body = "Text of the mail"
oMail.To = "adress@mail.com"
oMail.ReadReceiptRequested = True
oMail.Save() ' Or oMail.Send() if you wish to send inmediatly
I hope this will be useful to you
Rafael Altungy
SPAIN |
| Rafael Altungy Wednesday, November 14, 2007 7:31 PM |
The System.Net.SmtpClient is the way to go. It does not require Outlook to be installed, but you do need an SMTP server. Documentation is here: http://msdn2.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
-Ryan / Kardax
|
| Ryan Lamansky Wednesday, November 14, 2007 9:52 PM |
Here is one template. You need an available SMTP server to send mail.
Code Block
Imports System.Net.Mail
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mailInstance As MailMessage = New MailMessage("FromMailAdress", "ToMailAdress", "Subject", "Body")
mailInstance.Attachments.Add(New Attachment("filename")) 'Optional
Dim mailSenderInstance As SmtpClient = New SmtpClient("smtpHostAdress", 25) '25 is the port of the SMTP host
mailSenderInstance.Credentials = New System.Net.NetworkCredential("LoginAccout", "Password")
mailSenderInstance.Send(mailInstance)
mailInstance.Dispose()
End Sub
End Class
|
| Martin Xie - MSFT Friday, November 16, 2007 5:52 AM |
Hello:
I use Microsoft Outlook, and the code I use is:
Imports Outlook = Microsoft.Office.Interop.Outlook ' At the General Section of the Form
Private Sub cmdMail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMail.Click
Dim oOutlook As New Outlook.Application
Dim olNs As Outlook.NameSpace
Dim oMail As Outlook.MailItem
oOutlook = CreateObject( "Outlook.Application")
olNs = oOutlook.GetNamespace( "MAPI")
olNs.Logon()
oMail = oOutlook.CreateItem(Outlook.OlItemType.olMailItem)
oMail.Subject = "Subject of the mail"
oMail.Body = "Text of the mail"
oMail.To = "adress@mail.com"
oMail.ReadReceiptRequested = True
oMail.Save() ' Or oMail.Send() if you wish to send inmediatly
I hope this will be useful to you
Rafael Altungy
SPAIN |
| Rafael Altungy Wednesday, November 14, 2007 7:31 PM |
here you go. if u use gmail, works fine!
Code Block
Imports System.Net.Mail Imports System.Web
'sending Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim theMailMessage As MailMessage = New MailMessage("from", "To")
With theMailMessage .Body = RichTextBox1.Text .Subject = TextBox3.Text End With
'E-Mail Credentials and Sending Dim theClient As SmtpClient = New SmtpClient("SMTPprovider", 587) theClient.Timeout = 30000 theClient.EnableSsl = True
Dim theCredential As System.Net.NetworkCredential = New System.Net.NetworkCredential("userName", "password") theClient.Credentials = theCredential
'Send the email theClient.Send(theMailMessage) MessageBox.Show(("E-Mail Sent Successfully!" _ + (Environment.NewLine + "Thank You")), "Confirmation", MessageBoxButtons.OK)
Catch smtpex As SmtpException MessageBox.Show(("An error occured when trying to send a mail. You appear to be disconnected from the Internet. Pleas" & _ "e confirm that you are connected to the Internet and Resubmit all the data. " + smtpex.Message)) Catch ex As System.Exception MessageBox.Show(("An unexpected error occured. " + ex.Message))
End Try
End Sub |
| mNero Wednesday, November 14, 2007 7:40 PM |
Sorry, but neither of those work. Anyone else have an example?
|
| cjk1 Wednesday, November 14, 2007 8:05 PM |
Sorry I forgot to say that you need to add the reference to Microsoft Outlook Library in the COM TAB
Regards
Rafael Altungy
SPAIN |
| Rafael Altungy Wednesday, November 14, 2007 8:11 PM |
The System.Net.SmtpClient is the way to go. It does not require Outlook to be installed, but you do need an SMTP server. Documentation is here: http://msdn2.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
-Ryan / Kardax
|
| Ryan Lamansky Wednesday, November 14, 2007 9:52 PM |
None of this is working. Can anyone help me??? |
| cjk1 Thursday, November 15, 2007 3:13 AM |
do u catch any error? try with a diferent SMTP provider....
|
| mNero Thursday, November 15, 2007 3:27 PM |
Here is one template. You need an available SMTP server to send mail.
Code Block
Imports System.Net.Mail
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mailInstance As MailMessage = New MailMessage("FromMailAdress", "ToMailAdress", "Subject", "Body")
mailInstance.Attachments.Add(New Attachment("filename")) 'Optional
Dim mailSenderInstance As SmtpClient = New SmtpClient("smtpHostAdress", 25) '25 is the port of the SMTP host
mailSenderInstance.Credentials = New System.Net.NetworkCredential("LoginAccout", "Password")
mailSenderInstance.Send(mailInstance)
mailInstance.Dispose()
End Sub
End Class
|
| Martin Xie - MSFT Friday, November 16, 2007 5:52 AM |
What Email provider are you using? If they require Implicit SSL I do not think system.net.mail will work. |
| Pat116 Wednesday, August 12, 2009 7:52 PM |
here you go. if u use gmail, works fine!
Code Block
Imports System.Net.Mail Imports System.Web 'sending Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim theMailMessage As MailMessage = New MailMessage("from", "To") With theMailMessage .Body = RichTextBox1.Text .Subject = TextBox3.Text End With 'E-Mail Credentials and Sending Dim theClient As SmtpClient = New SmtpClient("SMTPprovider", 587) theClient.Timeout = 30000 theClient.EnableSsl = True Dim theCredential As System.Net.NetworkCredential = New System.Net.NetworkCredential("userName", "password") theClient.Credentials = theCredential 'Send the email theClient.Send(theMailMessage) MessageBox.Show(("E-Mail Sent Successfully!" _ + (Environment.NewLine + "Thank You")), "Confirmation", MessageBoxButtons.OK) Catch smtpex As SmtpException MessageBox.Show(("An error occured when trying to send a mail. You appear to be disconnected from the Internet. Pleas" & _ "e confirm that you are connected to the Internet and Resubmit all the data. " + smtpex.Message)) Catch ex As System.Exception MessageBox.Show(("An unexpected error occured. " + ex.Message)) End Try End Sub
oh...! thnx buddy... this is the only code i found working... i tried many codes...even frm other forums... none worked... thnx a lot again
theres nothing better than prime nos...!! |
| kool_Pragy Thursday, October 15, 2009 5:02 PM |