CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2008
    Posts
    161

    [RESOLVED] Sending a string through an email?

    Is it possible to get a couple of strings and send them to an email address.

    Code:
    private void button1_Click(object sender, EventArgs e)
    {
    string Name;
    string LastName;
    string Address;
    
    Name = textbox1.text;
    LastName = textbox2.text;
    Address = textbox3.text; 
    }
    And Send the strings Name, Lastname, and Address to an email address.

    I'm Guessing you would have to write it to a .txt file. Then somehow email it.

    But i am not exactly sure how.

    How do you do this?

    Thanks in advance.

  2. #2
    Join Date
    May 2008
    Posts
    84

    Re: Sending a string through an email?


  3. #3
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Sending a string through an email?

    This should just about do what you need...

    Code:
    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.host.com"); //change this to match your smtp server
    
    smtp.Send(new System.Net.Mail.MailMessage("[email protected]", [email protected]", "subject", "message"));
    It's not a bug, it's a feature!

  4. #4
    Join Date
    Mar 2008
    Posts
    161

    Re: Sending a string through an email?

    Quote Originally Posted by foamy
    This should just about do what you need...

    Code:
    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.host.com"); //change this to match your smtp server
    
    smtp.Send(new System.Net.Mail.MailMessage("[email protected]", [email protected]", "subject", "message"));
    That worked great, but i can't seem to get it to work with windows live or yahoo mail. Is is possible to do that?

    Code:
    "plus.pop.mail.yahoo.com" in the Incoming Mail (POP3, IMAP, or HTTP) Server box.
    "plus.smtp.mail.yahoo.com" in the Outgoing Mail (SMTP) Server box.
    Every time it tries to send a message when i use yahoo's SMTP the program crashes and Visual studio tells me it had an authentication error.

    Code:
    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("plus.smtp.mail.yahoo.com"); 
    smtp.Send(new System.Net.Mail.MailMessage("[email protected]", "[email protected]", "New Contact!", "New Contact information"));
    I think i have to add a yahoo username and password for myemail and then it should send it to my friends right?

    But once again i am not sure how do this.
    Last edited by Pale; June 27th, 2008 at 10:01 AM.

  5. #5
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Sending a string through an email?

    I've only used this function on my own smtp server... so I'm not sure if what you're trying to accomplish is possible, not to mention allowed... I'm pretty sure that if you asked Yahoo, they'd tell you to please stop trying..
    It's not a bug, it's a feature!

  6. #6
    Join Date
    Mar 2008
    Posts
    161

    Re: Sending a string through an email?

    No i think there is a way to put your yahoo username and password in the code. That way yahoo's smtp server could authenticate it. And send the email.

    I'm pretty sure that is possible. Anyone have ideas?

  7. #7
    Join Date
    May 2008
    Posts
    84

    Re: Sending a string through an email?

    http://msdn.microsoft.com/en-us/libr...edentials.aspx

    Take a look at that, it talks about sending credentials to the mail server.

  8. #8
    Join Date
    Mar 2008
    Posts
    161

    Re: Sending a string through an email?

    Quote Originally Posted by mwpeck
    http://msdn.microsoft.com/en-us/libr...edentials.aspx

    Take a look at that, it talks about sending credentials to the mail server.
    Can you show me an example of using a yahoo username and password?

  9. #9
    Join Date
    Mar 2008
    Posts
    161

    Re: Sending a string through an email?

    Ive been looking around i came up with this:
    Code:
                System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("[email protected]", "[email protected]", "New", "Account Name: " + accountname + "\nAccount Password: " + accountpassword);
                MyMailMessage.IsBodyHtml = false;
                System.Net.NetworkCredential mailAuthentication = new
                System.Net.NetworkCredential("MyUsername", "Mypassword");
                System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 465);
                mailClient.EnableSsl = true;
                mailClient.UseDefaultCredentials = false;
                mailClient.Credentials = mailAuthentication;
                mailClient.Send(MyMailMessage);
    But every time i use it with my Gmail addresses the program stops responding.

    Any ideas?

  10. #10
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Sending a string through an email?

    That is your ISP's filter. They will only send email sent by the owner of the account's primary email address. Call them to get it removed
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured