如何通过本地主机从JavaMail发送邮件(How to Send Mail from JavaMail via Localhost)
我正在创建一个表单,当用户完成他的详细信息并单击提交时,该表单将通过电子邮件发送详细信息。
邮件提交与JavaMail:
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); try { String host = "localhost"; String from = "root@localhost.localdomain"; try { Properties props = System.getProperties(); props.put("mail.smtp.host", host); props.put("mail.smtp.user", from); props.put("mail.debug", "true"); Session session = Session.getDefaultInstance(props, null); session.setDebug(true); Transport transport = session.getTransport("smtp"); MimeMessage message = new MimeMessage(session); Address fromAddress = new InternetAddress("root@localhost.localdomain"); message.setFrom(fromAddress); InternetAddress to = new InternetAddress("sendToAliases@localhost.localdomain"); message.addRecipient(Message.RecipientType.TO, to); message.setSubject("Email Details Sending"); message.setText("This is my testing content."); transport.connect(host, from); message.saveChanges(); Transport.send(message); transport.close(); } finally { out.close(); } }
我使用sendToAliases@localhost.localdomain的电子邮件别名,这意味着我可以从sendToAliases有4个电子邮件别名。 但是,在部署和运行上述邮件文件时,我无法收到任何电子邮件。 任何人都可以请教我吗?
谢谢。
I am creating a form, which will send out the details via email upon user completes his details and click submit.
Mail Submission with JavaMail:
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); try { String host = "localhost"; String from = "root@localhost.localdomain"; try { Properties props = System.getProperties(); props.put("mail.smtp.host", host); props.put("mail.smtp.user", from); props.put("mail.debug", "true"); Session session = Session.getDefaultInstance(props, null); session.setDebug(true); Transport transport = session.getTransport("smtp"); MimeMessage message = new MimeMessage(session); Address fromAddress = new InternetAddress("root@localhost.localdomain"); message.setFrom(fromAddress); InternetAddress to = new InternetAddress("sendToAliases@localhost.localdomain"); message.addRecipient(Message.RecipientType.TO, to); message.setSubject("Email Details Sending"); message.setText("This is my testing content."); transport.connect(host, from); message.saveChanges(); Transport.send(message); transport.close(); } finally { out.close(); } }
I am using Email aliases for sendToAliases@localhost.localdomain which means I could have 4 email aliases from sendToAliases. However, I am unable to reach any emails upon deploying and running the above mail file. Can anyone please advise me?
Thank you.
原文:https://stackoverflow.com/questions/2088547
最满意答案
Regex.Replace(str, @"\++", "+");
Regex.Replace(str, @"\++", "+");
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
在Ruby 1.8.7+中使用正则表达式: p s.scan(/((\d)\2*)/).map(&:first) #=> ["111", "22", "1"] 这是可行的,因为(\d)捕获任何数字,然后\2*捕获该组(第二个左括号)匹配的零个或多个。 scan需要外部(…)来捕获整个匹配。 最后,单独scan返回: [["111", "1"], ["22", "2"], ["1", "1"]] ...所以我们需要通过并保持每个数组中的第一项。 在Ruby 1.8.6+(为了方便起见,它没有Symbol# ...
-
是的,这是可能的,但我不会在SQL Server没有正则表达式的功能: CREATE TABLE tabC(CompanyName VARCHAR(100)); INSERT INTO tabC(CompanyName) SELECT 'HSBC Inc' UNION ALL SELECT 'Barcccclays' UNION ALL SELECT 'AAAAA' UNION ALL SELECT 'Testtttt' UNION ALL SELECT 'Tes ...
-
如何删除R中的多个连续特殊字符?(How to remove multiple consecutive special characters in R? [duplicate])[2022-07-06]
我们可以使用gsub gsub("([[:punct:]])\\1+", "\\1", str1) #[1] "Nice one!" "Whazzup?!" 数据 str1 <- c("Nice one!!!", "Whazzup????!!") We can use gsub gsub("([[:punct:]])\\1+", "\\1", str1) #[1] "Nice one!" "Whazzup?!" data str1 <- c("Nice one!!!", "Whazzup????!!" ... -
>>> import re >>> s="I liiiiked it, thaaaaaaank you" >>> re.sub(r"(.)(\1{3})(\1+)", r"\1\2", s) 'I liiiiked it, thaaaank you' 此正则表达式查找3个组。 第一个是任何角色。 第二个是同一个角色的3个,第三个是第一个角色中的一个或多个。 然后将这3组替换为组1和组2 这是一个更简单的方法 >>> re.sub(r"(.)\1{4,}", r"\1"*4, s) 'I liiiiked ...
-
你应该用len = k;更新字符串的长度len = k; 在 for循环结束后 。 但是请注意,当您缩短字符串以使其成为正确的C字符串时,您还应该在新长度处设置空终止符。 这是一个更简单的版本: #include
int main() { char str[100]; int i, j; printf("Enter any string: "); if (fgets(str, sizeof str, stdin)) { for (i = ... -
将字符串中的多个连续相等字符减少为一个(Reduce multiple consecutive equal characters from a string to just one)[2023-06-05]
Regex.Replace(str, @"\++", "+"); Regex.Replace(str, @"\++", "+"); -
您可以使用此正则表达式替换: int n = 3 // or whatever number; String repl = ""; if (n > 0) { repl = str.replaceAll("((\\S)\\2{" + (n-1) + "})\\2*", "$1"); } 示例:(对于N = 3) RegEx演示1 示例:(对于N = 2) RegEx演示2 说明: ( :开始捕获组#1 (\S) :匹配1+非空白字符并捕获为组#2 \2{2} :匹配同一个char的2个实例 ) :结 ...
-
只是出于好奇: 红宝石> = 2.4 'aabaaa'.each_char.chunk_while(&:==).map(&:join) # or .map(&:length) #⇒ ["aa", "b", "aaa"] ruby> = 2.3 (Cary Swoveland的积分) 'aabaaa'.each_char.chunk(&:itself).map(&:join) ∀红宝石 'aabaaa'.scan(/(\w)(\1*)/).map(&:join) #⇒ ["aa", "b", "aaa"] ...
-
在Javascript字符串中标识连续的十六进制字符块(Identify consecutive block of Hexadecimal characters in a Javascript string)[2022-06-20]
就像是: /^[a-f0-9]+$/i.test("ABCDEF") 要么 var r = new RegExp("^[a-f0-9]+$", 'i') r.test("ABCDEF"); Something like: /^[a-f0-9]+$/i.test("ABCDEF") Or var r = new RegExp("^[a-f0-9]+$", 'i') r.test("ABCDEF");