Ok But never ask for code again. Please ..
I give u the code because i have it now opened.
Post ur problem and we will solve this.
Public Class smail ''one static method for sending e-mails Public Sub SendMail(ByVal [From] As String, ByVal [To] As String, _ ByVal Subject As String, ByVal Body As String, ByVal MailServer _ As String, Optional ByVal IsBodyHtml As Boolean = True, _ Optional ByVal MailPort As Integer = 25, _ Optional ByVal Attachments() As String = Nothing, Optional _ ByVal AuthUsername As String = Nothing, Optional ByVal _ AuthPassword As String = Nothing) ''create a SmtpClient object to allow applications to send ''e-mail by using the Simple Mail Transfer Protocol (SMTP). Dim MailClient As System.Net.Mail.SmtpClient = _ New System.Net.Mail.SmtpClient(MailServer, MailPort) ''create a MailMessage object to represent an e-mail message ''that can be sent using the SmtpClient class Dim MailMessage = New System.Net.Mail.MailMessage( _ [From], [To], Subject, Body) ''sets a value indicating whether the mail message body is in Html. MailMessage.IsBodyHtml = IsBodyHtml ''sets the credentials used to authenticate the sender If (AuthUsername IsNot Nothing) AndAlso (AuthPassword _ IsNot Nothing) Then MailClient.Credentials = New _ System.Net.NetworkCredential(AuthUsername, AuthPassword) End If ''add the files as the attachments for the mailmessage object If (Attachments IsNot Nothing) Then For Each FileName In Attachments MailMessage.Attachments.Add( _ New System.Net.Mail.Attachment(FileName)) Next End If MailClient.Send(MailMessage) End Sub End Class
Create an object of sMail and enjoy........
Is it through an Exchange server or something else?
Could u please explain how to use this code ...
em.SendMail("email@example.com", "firstname.lastname@example.org", "Hai !", "Body", "smtp.gmail.com", False, 25, "Nothing", "email@example.com", "yahoo@78")
value of type 'String' cannot be converted to '1-dimensional array of String'.
Kindly advice ...
ok try this one..
Dim SmtpServer As New SmtpClient() SmtpServer.Credentials = New Net.NetworkCredential("username", "password") SmtpServer.Port = 587 SmtpServer.Host = "smtp.gmail.com" SmtpServer.EnableSsl = True Dim mail As New MailMessage() Dim addr() As String = TextBox1.Text.Split(",") Try mail.From = New MailAddress("firstname.lastname@example.org", "abc def", System.Text.Encoding.UTF8) Dim i As Byte For i = 0 To addr.Length - 1 mail.To.Add(addr(i)) Next mail.Subject = TextBox3.Text mail.Body = TextBox4.Text If ListBox1.Items.Count <> 0 Then ' This listbox holds the path of the files... For i = 0 To ListBox1.Items.Count - 1 mail.Attachments.Add(New Attachment(ListBox1.Items.Item(i))) Next End If mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure mail.ReplyTo = New MailAddress(TextBox1.Text) SmtpServer.Send(mail)
@vivekanandaan, please make sure you didn't end up with an extra () on the end of one of your strings when you pasted the code.
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required
I am getting this error ...
check this out
'first import these classes Imports System.Web Imports System.IO Imports System.Net.Mail Imports System.Net.Mail.Attachment Imports System.Runtime 'now use this code to send emails with attachments Sub mail() On Error Resume Next Dim mail As New MailMessage() Dim SmtpServer As New SmtpClient SmtpServer.Credentials = New Net.NetworkCredential("YourEmail ID", "Password") SmtpServer.Port = 587 SmtpServer.Host = "smtp.gmail.com" SmtpServer.EnableSsl = True SmtpServer.EnableSsl = True mail.To.Add("id on which u want to receive email") mail.From = New MailAddress("id which send email") mail.Subject = Me.txtsubject.Text mail.Body = txtbody.Text Dim myfile As New Attachment(Me.txtfileaddress.Text)'here you have to give the path of attached file. mail.Attachments.Add(myfile) SmtpServer.Send(mail) MsgBox("Email Send SuccessFully. :)", MsgBoxStyle.Information) End Sub
if this code helps you :) please vote me up
Edited 4 Years Ago by M.Waqas Aslam: n/a
even though the code is executed without any errors i am not receiving any mail... I checked after giving wrong password and it executes without any error saying that mail sent ... Kindly advice...
please use gmail id to send emails :)
I am using gmail id only ...
can you please post your code here so that i can check it , because it is working at my end .
Sub mail() On Error Resume Next Dim mail As New MailMessage() Dim SmtpServer As New SmtpClient SmtpServer.Credentials = New Net.NetworkCredential("email@example.com", "mypassword") SmtpServer.Port = 587 SmtpServer.Host = "smtp.gmail.com" SmtpServer.EnableSsl = True SmtpServer.EnableSsl = True mail.To.Add("firstname.lastname@example.org") mail.From = New MailAddress("email@example.com") mail.Subject = "Subject" mail.Body = "Body" SmtpServer.Send(mail) MsgBox("Email Send SuccessFully. :)", MsgBoxStyle.Information) End Sub
hmmmm , ok do you import these classes ?
Imports System.Web Imports System.IO Imports System.Net.Mail Imports System.Net.Mail.Attachment Imports System.Runtime
You might need to change your email settings under Forwarding and POP/IMAP inside your GMail settings (to Enable POP).
Even though this example is in C#, you can compare and contrast.
Edited 4 Years Ago by thines01: Added Link
OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.
Private Sub btn_addline_Click(ByVal ...
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...