Solved

VB.net Windows App Sending mail

Posted on 2014-04-09
2
367 Views
Last Modified: 2014-04-13
Hi
I use the VB.net code further down to send emails in my ASP.net web application.
I put the following in the web.config file. I want to now use this code to send mails
from Windows Forms app but there is obviously no web.config file. How do I set this
up in my Windows forms app

  <!-- Email **** Add the email settings to the <system.net> element -->
  <system.net>
    <mailSettings>
      <smtp from="info@online-excel.com">
        <network host="41xx" port="25" userName="info@online-excel.com" password="x"/>

      </smtp>
    </mailSettings>
  </system.net>
  <!-- Email **** Add the email settings to the <system.net> element -->

                    Dim sBody As String = oBuild_Email_Body_From_Query() & "<br />" & oBuild_Email_Body_From_Query2()
                    Dim objScheduleMail As New clsScheduleMail()
                    objScheduleMail.oSendScheduleMail("info@online-excel.com", "info@online-excel.com", "murbro9@yahoo.com", "", "GREAT Entries", sBody)

Imports System.Net.Mail

Public Class clsScheduleMail

    Public Function oSendScheduleMail(ByVal from As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String, ByVal subject As String, ByVal body As String) As String
        Try

            ' Instantiate a new instance of MailMessage
            Dim mMailMessage As New MailMessage()

            ' Set the sender address of the mail message
            mMailMessage.From = New MailAddress(from)
            ' Set the recepient address of the mail message
            mMailMessage.To.Add(New MailAddress(recepient))

            ' Check if the bcc value is nothing or an empty string
            If Not bcc Is Nothing And bcc <> String.Empty Then
                ' Set the Bcc address of the mail message
                mMailMessage.Bcc.Add(New MailAddress(bcc))
            End If

            ' Check if the cc value is nothing or an empty value
            If Not cc Is Nothing And cc <> String.Empty Then
                ' Set the CC address of the mail message
                mMailMessage.CC.Add(New MailAddress(cc))
            End If

            ' Set the subject of the mail message
            mMailMessage.Subject = subject
            ' Set the body of the mail message
            mMailMessage.Body = body

            ' Set the format of the mail message body as HTML
            mMailMessage.IsBodyHtml = True
            ' Set the priority of the mail message to normal
            mMailMessage.Priority = MailPriority.Normal

            ' Instantiate a new instance of SmtpClient
            Dim mSmtpClient As New SmtpClient()
            ' Send the mail message
            mSmtpClient.Send(mMailMessage)

            oSendScheduleMail = "Mail Sent"
        Catch ex As Exception
            oSendScheduleMail = ex.Message
        End Try
    End Function

End Class
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39990107
Don't put settings in config file and change following line

Dim mMailMessage As New MailMessage()

to

Dim mMailMessage As New MailMessage(From, Recipient)
0
 

Author Closing Comment

by:Murray Brown
ID: 39997610
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question