Solved

How to send emails in visual studio 2005

Posted on 2010-08-16
4
331 Views
Last Modified: 2013-12-18
Hello, can someone help me with understanding (including any imports) how to build an HTML/ASPX page that has a button to click to send an email to pre-coded email addresses with multiple attachments.  

I have muliple folders on my iis server that have a pdf file inserted into them once a month via impromptu.  I would like to have my user click one button (or something like that) and have the appropriate file in each folder retreived and sent to the appropriate email address.  I prefer not to have the user manually enter each address.  Thank you
0
Comment
Question by:ilfocorp
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
dschauhan82 earned 200 total points
ID: 33451385
http://www.codeproject.com/KB/aspnet/EmailApplication.aspx.
http://www.codeproject.com/KB/aspnet/ASPNETwebmail.aspx?msg=1455810
These links for attach the attachment from browse button, but you need to only change for directiry attachment.

Hope this help....
0
 
LVL 4

Expert Comment

by:dschauhan82
ID: 33451662
Code to send mail with attechment.,        public static bool SendMail(string strFrom, string strTo, string strSubject, string strMsg)        {                        try
            {                
                // Create the mail message
                MailMessage objMailMsg = new MailMessage(strFrom, strTo);                                objMailMsg.BodyEncoding = Encoding.UTF8;                objMailMsg.Subject = strSubject;                objMailMsg.Body = strMsg;                Attachment at = new Attachment(Server.MapPath("~/Uploaded/txt.doc"));                objMailMsg.Attachments.Add(at);                objMailMsg.Priority = MailPriority.High;                objMailMsg.IsBodyHtml = true;                //prepare to send mail via SMTP transport
                SmtpClient objSMTPClient = new SmtpClient();                objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;                objSMTPClient.Send(objMailMsg);                return true;                            }            catch (Exception ex)            {                throw ex;            }        }         hope it helps./.
0
 

Assisted Solution

by:tapozsl
tapozsl earned 200 total points
ID: 33454398
Some code is there..just check this.
#Region " Send Mail Button Click                 "

    Protected Sub btnSendMail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSendMail.Click

        Try

            Dim attach1 As String = ""

            Dim strFileName As String = ""

            Dim objCom As New Common

            Dim sContentType As String = ""

            If FileUpload1.PostedFile.FileName <> "" Then

                Dim ulFile As HttpPostedFile = FileUpload1.PostedFile

                Dim nFileLen As Int64 = ulFile.ContentLength

                If (nFileLen > 0) Then

                    strFileName = Path.GetFileName(FileUpload1.PostedFile.FileName)

                    strFileName = "Uploads/" + strFileName



                    'Saveing the file in proper directory

                    FileUpload1.PostedFile.SaveAs(Server.MapPath(strFileName))

                    objCom.SendMail(tbFrom.Text, tbTo.Text, tbSubject.Text, tbMessage.Text, Server.MapPath(strFileName), cbInline.Checked)

                End If

            Else

                objCom.SendMail(tbFrom.Text, tbTo.Text, tbSubject.Text, tbMessage.Text)

            End If

        Catch ex As Exception

        End Try

    End Sub

#End Region





Public Function SendMail(ByVal sFrom As String, ByVal sTo As String, ByVal sSubject As String, ByVal sMessage As String, ByVal sFile As String, Optional ByVal sInline As Boolean = False) As Boolean

        Try

            Dim Mail As New SmtpClient(System.Configuration.ConfigurationManager.AppSettings("SMTP"))

            'set the addresses and content

            Dim mMessage As New MailMessage(sFrom, sTo, sSubject, sMessage)



            '*************************Send Attchment *************************'

            If Not sFile = "" Then

                Dim attach As New System.Net.Mail.Attachment(sFile)

                attach.ContentDisposition.Inline = True



                If sInline <> False Then

                    '*************************Send Inline Image ***********************'

                    ' create the Html part

                    'to embed images, we need to use the prefix 'cid' in the img src value

                    'the cid value will map to the Content-Id of a Linked resource.

                    'thus <img src='cid:image'> will map to a LinkedResource with a ContentId of 'image'



                    Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString("", Nothing, "text/plain")

                    Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(".<img src=cid:image>", Nothing, "text/html")

                    'select the image 

                    Dim at As New Attachment(sFile)



                    'create LinkedResource (embedded image)   

                    Dim logo As New LinkedResource(sFile, "text/plain")

                    logo.ContentId = "image"

                    'add the LinkedResource to the appropriate view

                    htmlView.LinkedResources.Add(logo)

                    'add the views

                    mMessage.AlternateViews.Add(plainView)

                    mMessage.AlternateViews.Add(htmlView)

                    '--------------------------------------End----------------------------'

                Else

                    mMessage.Attachments.Add(attach)

                End If

            End If

            '--------------------------------------End----------------------------'

            'Specifing HTML mail

            mMessage.IsBodyHtml = True

            'Sending the email finally

            Mail.Send(mMessage)

            Return True

        Catch ex As Exception



        End Try

    End Function



    Public Function SendMail(ByVal sFrom As String, ByVal sTo As String, ByVal sSubject As String, ByVal sMessage As String) As Boolean

        Dim Mail As New SmtpClient(System.Configuration.ConfigurationManager.AppSettings("SMTP"))

        Mail.Send(sFrom, sTo, sSubject, sMessage)

        Return True

    End Function

Open in new window

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

New-MailboxSearch Powershell Command and step by step approach to Search and Extract Emails form Exchange 2013 Journaling server.
This is about my first experience with programming Arduino.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now