vb.net - VB Set Mail Priority High -


the code sends out email , works okay reason not going out high importance. doing wrong.

option explicit on imports system.io imports system.net.mail module sendmail sub sendmessage()         dim olapp object         dim olmail object         dim olns object         dim priority mailpriority     olapp = createobject("outlook.application")     olns = olapp.getnamespace("mapi")     olmail = olapp.createitem(0)      olmail          olmail.to = "" '// add recipient          olmail.cc = ""          olmail.bcc = ""          olmail.subject = "new file "           olmail.htmlbody = "your file ready " & format(now, "long date")          olmail.attachments.add = " " '// add attachments message.          olmail.priority = mailpriority.high '// high importance          olmail.send()     end     olmail = nothing     olapp = nothing     olns = nothing end sub end module 

try sending using system.net.mail namespace instead.

example:

option strict on option explicit on option infer off imports system.net.mail public class form1     function sendemail(byval recipients list(of string), _                       byval fromaddress string, _                       byval subject string, _                       byval body string, _                       byval username string, _                       byval password string, _                       optional byval server string = "smtp.gmail.com", _                       optional byval port integer = 587, _                       optional byval attachments list(of string) = nothing) string         dim email new mailmessage()         try             dim smtpserver new smtpclient             each attachment string in attachments                 email.attachments.add(new attachment(attachment))             next             email.from = new mailaddress(fromaddress)             each recipient string in recipients                 email.to.add(recipient)             next             email.subject = subject             email.body = body             '----------------------------------             email.priority = mailpriority.high             '----------------------------------             smtpserver.host = server             smtpserver.port = port             smtpserver.credentials = new system.net.networkcredential(username, password)             smtpserver.enablessl = true             smtpserver.send(email)             email.dispose()             return "email " & recipients(0) & " " & fromaddress & " sent."         catch ex smtpexception             email.dispose()             return "sending email failed. smtp error."         catch ex argumentoutofrangeexception             email.dispose()             return "sending email failed. check port number."         catch ex invalidoperationexception             email.dispose()             return "sending email failed. check port number."         end try     end function     private sub button1_click(sender object, e eventargs) handles button1.click         dim recipients new list(of string)         recipients.add("someemailaddress")         dim fromemailaddress string = recipients(0)         dim subject string = "test vb."         dim body string = "email body text, if reading gmail account, program worked."         dim username string = "gmail username without  (@gmail>com)"         dim password string = "password"         dim port integer = 587         dim server string = "smtp.gmail.com"         dim attachments new list(of string)         msgbox(sendemail(recipients, fromemailaddress, subject, body, username, password, server, port, attachments))     end sub end class 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -