Results 1 to 9 of 9

Thread: sending an email : howto needed

  1. #1

    Thread Starter
    Lively Member mindloop's Avatar
    Join Date
    Mar 2004
    Posts
    64

    Question sending an email : howto needed

    Hi there,
    i'm writing an application where user generates reports. what i need now is to allow users to email their reports.
    I would like to accomplish this without having to force the user to install other deployment tools than the framework.
    Maybe something like opening outlook express (not from the office pack) with my desired mailcontent already filled in, so that the user can just quick modify parts of the message and just press send.
    any suggestions, directions i should look into, or samples are welcome, thanks.
    ehmm...

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Search the forum for system.web.mail, there's been several discusssions the past couple weeks. here's an example of using Outlook (not Outlook Express) to send mail with an attachment:
    VB Code:
    1. Public Sub LetsSendMail()
    2.         Dim OlApp As New Outlook.Application()
    3.         Dim OlNameSpace As Outlook.NameSpace
    4.         Dim msg As Outlook.MailItem
    5.         Dim strPath, strSubj As String
    6.        
    7.         'get attachment - Current is a structure in the module
    8.         strPath = strRelPath & gstrPepType & "\" & Current.Proj & "\" & Current.Proj & "Changes.txt"
    9.         strSubj = Current.Proj & " " & Current.Mnth.ToUpper & ", " & Current.YNum & " Edited Changes"
    10.  
    11.         Try
    12.             msg = OlApp.CreateItem(Outlook.OlItemType.olMailItem)
    13.             msg.Recipients.Add(bossman)
    14.             msg.Subject = strSubj
    15.             msg.Attachments.Add(strPath)
    16.             msg.Body = "Changes attached for " & Current.Mnth.ToUpper & Current.Proj.ToUpper
    17.             msg.Display()
    18.         Catch ex As Exception
    19.             MessageBox.Show(ex.Message)
    20.         End Try

  3. #3

    Thread Starter
    Lively Member mindloop's Avatar
    Join Date
    Mar 2004
    Posts
    64
    what do i do if the user hasn't got outlook installed ?
    msgbox("please install microsoft outlook!") won't do.
    thanks for the searchtip.
    ehmm...

  4. #4
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354
    Assuming you have access to a mail server this should get you started.
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, _
    2.         ByVal e As System.EventArgs) Handles Button1.Click
    3.  
    4.         Dim newMail As New System.Web.mail.MailMessage
    5.         newMail.To = txtTO.Text
    6.         newMail.From = txtFrom.Text
    7.         newMail.Body = txtBody.Text
    8.         newMail.Subject = txtSubject.Text
    9.         System.Web.Mail.SmtpMail.SmtpServer = "MailServerName"
    10.         System.Web.Mail.SmtpMail.Send(newMail)
    11.  
    12.     End Sub
    For some reason the search feature on this forum is not working for me right now but there are some recent examples using server authentication (if you need it) and adding attachments.

  5. #5

    Thread Starter
    Lively Member mindloop's Avatar
    Join Date
    Mar 2004
    Posts
    64
    i've seen this code in many help sections now, but what puzzles me is how i can customize this for each user , i suppose each of them have their own different mailserver.
    how can i retrieve that ?
    i need a code that runs on any computer. not just on mine.
    ehmm...

  6. #6
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

  7. #7
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354
    i need a code that runs on any computer. not just on mine.
    I suspect you are going to need to have a settings section in your application where the users will have to set the mail settings themselves. Something like Outlook or Netscape does.

    I recommend you take a look at this site to help out with system.web.mail - System.Web.Mail, OH MY! - I linked to this FAQ in my last post.

  8. #8
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    The drawback I found with system.web.mail is that some intranets (ours, for example) don't use a smtp server. I did get it to send mail anyway, but it wouldn't pop up the mail program to allow editing.

  9. #9

    Thread Starter
    Lively Member mindloop's Avatar
    Join Date
    Mar 2004
    Posts
    64
    thanks i'm feeding in information from all the links you posted. i'll return if questions appear. (hopefully not)
    ehmm...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width