Solved

How to send emails in visual studio 2005

Posted on 2010-08-16
4
339 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
[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
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
As cyber crime continues to grow in both numbers and sophistication, a troubling trend of optimization has emerged over the last year.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 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