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
Shal
1.5k
245
3.7k
FileUpload control loses the attactment on every mail send postback.
Apr 14 2021 5:56 AM
Hi am sending multiple mails with and without attachments. problem is i have two mail ids coloums 1 is personal mailID 2 is company mailID. if i send mail for both mailIDs 1st one go with attachment but 2nd one go without attachment beause of postback effect so please help me.
kindly find the code below
Parallel.ForEach(dtCustomers.AsEnumerable(), row =>
{
SendEmail(row[
"PERSONAL_EMAILID"
].ToString(), subject,
string
.Format(body, row[
"ENAME"
]));
SendEmail(row[
"OFFICIAL_EMAILID"
].ToString(), subject,
string
.Format(body, row[
"ENAME"
]));
});
private
bool
SendEmail(
string
recipient,
string
subject,
string
body)
{
string
from = txtemailfrom.Text;
using
(MailMessage mail =
new
MailMessage(txtemailfrom.Text, recipient))
{
mail.Subject = txtsubject.Text;
mail.Body = txtbody.Text;
if
(fileUploader.HasFile)
{
string
fileName = Path.GetFileName(fileUploader.PostedFile.FileName);
mail.Attachments.Add(
new
Attachment(fileUploader.PostedFile.InputStream, fileName));
}
mail.IsBodyHtml =
false
;
SmtpClient smtp =
new
SmtpClient();
smtp.Host =
"111.111.1.11"
;
smtp.EnableSsl =
false
;
NetworkCredential networkCredential =
new
NetworkCredential(from,
"
[email protected]
"
);
smtp.UseDefaultCredentials =
true
;
smtp.Credentials = networkCredential;
smtp.Port = 25;
smtp.Send(mail);
ScriptManager.RegisterStartupScript(
this
,
this
.GetType(),
"alert"
,
"alert('Message has been sent successfully.');window.location ='SendBulkMail.aspx';"
,
true
);
}
i tries saving in session and send but problem is when i send mail without attachment the mails captures the cookies in session and send mail with prev attachment.
Reply
Answers (
1
)
HTML Multi Select Options
How do I pass parameters to another page using ASP.NET friendly URL?