Click to See Complete Forum and Search --> : [RESOLVED] Sending a string through an email?


Pale
June 26th, 2008, 10:48 PM
Is it possible to get a couple of strings and send them to an email address.

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.

mwpeck
June 27th, 2008, 12:37 AM
This should be of some help:

http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx

foamy
June 27th, 2008, 01:15 AM
This should just about do what you need...



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("from@address.com", to@address.com", "subject", "message"));

Pale
June 27th, 2008, 08:41 AM
This should just about do what you need...



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("from@address.com", to@address.com", "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?

"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.

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("plus.smtp.mail.yahoo.com");
smtp.Send(new System.Net.Mail.MailMessage("Myemail@yahoo.com", "Friendsemail@yahoo.com", "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.

foamy
June 27th, 2008, 11:10 AM
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..

Pale
June 27th, 2008, 11:37 AM
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?

mwpeck
June 27th, 2008, 11:51 AM
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.credentials.aspx

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

Pale
June 27th, 2008, 02:20 PM
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.credentials.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?

Pale
June 27th, 2008, 03:21 PM
Ive been looking around i came up with this:
System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("Myemail@domain.com", "friendsemail@domain.com", "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?

dglienna
June 27th, 2008, 05:29 PM
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