TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
testovani prvni
NA
3
1.1k
Send email - doesn't work with variables
Jan 16 2014 10:26 AM
I'm working in Visual Studio 2012 expres, C#.
THIS IS MY CODE:
=======================================================
var fromAddress = new MailAddress("
[email protected]
", "Info Mail");
var toAddress = new MailAddress("
[email protected]
", "Info Mail");
const string fromPassword = "xxxxxxx";
string subject = textBox1.Text;
const string body = "body";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
=======================================================
PROBLEM IS:
string subject = textBox1.Text;
const string body = "body";
BODY works, because it's defined as a text. But SUBJECT doesn't work, because it's variable. If I change SUBJECT to text, it works. But I need it as a variable.
THIS ERROR I GET:
An unhandled exception of type 'System.ArgumentException' occurred in System.dll. Additional information: The specified string is not in the form required for a subject.
Reply
Answers (
2
)
Create dynamic subdomain like path using URL Rewriting
load image files from folder without use opendialog in c#