Hello, I am trying to send an email from ASP.NET but something is wrong with me, I found that to use the mailer I should not pass plain text to it than variables , but my valuable is a String , I do not know if I'm passing something else.
Here's my complete method below
[HttpPost]
public ActionResult UploadRequest(HttpPostedFileBase postedFile, string name, string fn, string ft, int fs, string wiw, int dep, int cat, int schem, string email,
string dat) {
int status = 0;
int seen = 0;
int edit = 0;
var send = "none";
var appro = "none";
int reject = 0;
var exp = "30 days";
byte[] bytes;
using(BinaryReader br = new BinaryReader(postedFile.InputStream)) {
bytes = br.ReadBytes(postedFile.ContentLength);
}
string constr = "Data Source=DMX87025;Initial Catalog=DB_PCC;Integrated Security=True";
using(SqlConnection con = new SqlConnection(constr)) {
string query = "INSERT INTO Requests ([nameproject],[wiw],[format],[email],[fsize],[ftype],[fname]" +
",[categoriesid],[departmentid],[schemeid],[status],[expiration]," +
"[seen],[edit],[createddate],[seendate],[answerdate],[rejected]" +
")" +
" VALUES (@name,@wiw,@formato,@email,@size,@fType,@fname," +
"@cat,@dep,@schem,@status,@exp,@seen,@edit,@dat,@seend,@ansd," +
"@rej" +
")";
using(SqlCommand cmd = new SqlCommand(query)) {
cmd.Connection = con;
cmd.Parameters.AddWithValue("@fname", Path.GetFileName(postedFile.FileName));
cmd.Parameters.AddWithValue("@fType", ft);
cmd.Parameters.AddWithValue("@formato", bytes);
cmd.Parameters.AddWithValue("@size", fs);
cmd.Parameters.AddWithValue("@wiw", wiw);
cmd.Parameters.AddWithValue("@email", email);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@cat", cat);
cmd.Parameters.AddWithValue("@dep", dep);
cmd.Parameters.AddWithValue("@schem", schem);
cmd.Parameters.AddWithValue("@dat", dat);
cmd.Parameters.AddWithValue("@status", status);
cmd.Parameters.AddWithValue("@exp", exp);
cmd.Parameters.AddWithValue("@seen", seen);
cmd.Parameters.AddWithValue("@edit", edit);
cmd.Parameters.AddWithValue("@seend", send);
cmd.Parameters.AddWithValue("@ansd", appro);
cmd.Parameters.AddWithValue("@rej", reject);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
sendUploadRequestMail(email, wiw);
return View();
}
public void sendUploadRequestMail( string email , string wiw ) {
string to = "[email protected]" ;
string from = email;
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the new SMTP client.";
message.Body = @"Using this new feature, you can send an e-mail message from an application very easily.";
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
// client.UseDefaultCredentials = true;
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in CreateTestMessage2(): {0}",
ex.ToString());
}
}
I leave it to you only to have context where the data comes from, but what is relevant is the last thing. Thanks.