ASP.Net : Send email with Images embedded in Rich Text HTML body -
sending mail along embedded image & html text using asp.net.
i have tried this:
public actionresult contact(tblcredential data) { string emailaddress = data.username; string password = data.password; if (!string.isnullorempty(emailaddress)) { //send email consultancy string htmltext = "<img src='r:/mvc@2/emailwithhtmlbody/emailwithhtmlbody/images/message.jpg'></img> <h1>thank you</h1>"; string = "******@gmail.com"; // mail-id here emailaddress string @touser = emailaddress; // mail-id mailmessage mail = new mailmessage(from, touser); { mail.subject = emailaddress + " sent message"; mail.body = htmltext; mail.isbodyhtml = true; smtpclient smtp = new smtpclient { host = "smtp.gmail.com", enablessl = true }; networkcredential networkcredential = new networkcredential(from, "*****"); //your password here.. smtp.usedefaultcredentials = false; smtp.credentials = networkcredential; smtp.port = 587; smtp.send(mail); } } return redirecttoaction("index"); }
email sent html code not working. in mail showing html tags. me.
try template.
it helps use smtp.port=25
try { mailmessage msg = new mailmessage (); mailaddress fromadd = new mailaddress("fromemail@email.com"); msg.[to].add("toemail@email.com"); msg.subject = "choose session members"; msg.from = fromadd; msg .isbodyhtml = true; msg.priority = mailpriority.normal; msg .bodyencoding = encoding.default; msg.body = "<center><table><tr><td><h1>your message</h1><br/><br/></td></tr>"; msg.body = msg.body + "</table></center>"; smtpclient smtpclient = new smtpclient ("smtp.yourserver.com", "25"); smtpclient.enablessl = true; smtpclient.usedefaultcredentials = false; smtpclient.credentials = new system.net.networkcredential("yourname@yourserver.com", "password"); smtpclient .deliverymethod = smtpdeliverymethod.network; smtpclient.send(msg); smtpclient.dispose(); }
Comments
Post a Comment